# Record Layer with DynamicMessage?

**URL:** <https://forums.foundationdb.org/t/record-layer-with-dynamicmessage/1576>\
**Category:** Record Layer\
**Created:** [August 9, 2019, 2:38am UTC](https://forums.foundationdb.org/t/record-layer-with-dynamicmessage/1576 "2019-08-09T02:38:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sraw](https://avatars.discourse-cdn.com/v4/letter/s/a88e57/32.png) [@Sraw](https://forums.foundationdb.org/u/Sraw)\
**Post date:** [August 9, 2019, 2:38am UTC](https://forums.foundationdb.org/t/record-layer-with-dynamicmessage/1576/1 "2019-08-09T02:38:58Z")

</div>

Suppose we are using a dynamically generated message like:

```
MessageDefinition msgDef = MessageDefinition.newBuilder("Person") // message Person
    .addField("required", "int32", "id", 1) // required int32 id = 1
    .addField("required", "string", "name", 2) // required string name = 2
    .addField("optional", "string", "email", 3) // optional string email = 3
    .build();

schemaBuilder.addMessageDefinition(msgDef);
DynamicSchema schema = schemaBuilder.build();

// Create dynamic message from schema
DynamicMessage.Builder msgBuilder = schema.newMessageBuilder("Person");
Descriptors.Descriptor msgDesc = msgBuilder.getDescriptorForType();
DynamicMessage msg = msgBuilder
    .setField(msgDesc.findFieldByName("id"), 1)
    .setField(msgDesc.findFieldByName("name"), "Alan Turing")
    .setField(msgDesc.findFieldByName("email"), "at@sis.gov.uk")
    .build();

```

But how could we make it work with record layer? I suppose we need to pass the schema of this message to the record layer as metadata. But it looks like that there is no corresponding API for it?

Or ultimately, how could we dynamically create schema instead of using statically generated schema?

---

<div class="post-metadata">

**Author:** ![Sraw](https://avatars.discourse-cdn.com/v4/letter/s/a88e57/32.png) [@Sraw](https://forums.foundationdb.org/u/Sraw)\
**Post date:** [August 9, 2019, 6:54am UTC](https://forums.foundationdb.org/t/record-layer-with-dynamicmessage/1576/2 "2019-08-09T06:54:19Z")

</div>

Well, I’ve figured it out 🙂 We can get the FileDescriptor from msgDesc:

```
Descriptors.FileDescriptor fileDescriptor = msgDesc.getFile();
```
