https://github.com/thingsboard/protobuf-dynamic
Protocol Buffers Dynamic Schema - create protobuf schemas programmatically
https://github.com/thingsboard/protobuf-dynamic
Last synced: 5 months ago
JSON representation
Protocol Buffers Dynamic Schema - create protobuf schemas programmatically
- Host: GitHub
- URL: https://github.com/thingsboard/protobuf-dynamic
- Owner: thingsboard
- License: apache-2.0
- Fork: true (os72/protobuf-dynamic)
- Created: 2020-10-13T11:27:57.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-11-01T08:46:39.000Z (over 3 years ago)
- Last Synced: 2025-08-03T03:39:21.079Z (11 months ago)
- Language: Java
- Homepage:
- Size: 130 KB
- Stars: 4
- Watchers: 2
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
protobuf-dynamic
================
Protocol Buffers Dynamic Schema - create protobuf schemas programmatically.
Available on Maven Central:
* https://repo.maven.apache.org/maven2/com/github/os72/protobuf-dynamic/1.0.1/
* https://repo.maven.apache.org/maven2/com/github/os72/protobuf-dynamic/0.9.5/
[](http://search.maven.org/#artifactdetails|com.github.os72|protobuf-dynamic|1.0.1|)
[](http://search.maven.org/#artifactdetails|com.github.os72|protobuf-dynamic|0.9.5|)
---
Library to simplify working with the Protocol Buffers reflection mechanism, no protoc compiler required.
Supports the major protobuf features: primitive types, complex and nested types, labels, default values, etc
* Dynamic schema creation - at runtime
* Dynamic message creation from schema
* Schema merging
* Schema serialization, deserialization
* Schema parsing from protoc compiler output
* Compatible with `protobuf-java` 2.6.1 or higher
* (Version 0.9.x compatible with `protobuf-java` 2.4.1 or higher)
See the Protocol Buffers site for details: https://github.com/google/protobuf
#### Usage
```java
// Create dynamic schema
DynamicSchema.Builder schemaBuilder = DynamicSchema.newBuilder();
schemaBuilder.setName("PersonSchemaDynamic.proto");
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");
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();
```
#### Maven dependency
```xml
com.github.os72
protobuf-dynamic
1.0.1
```
```xml
com.github.os72
protobuf-dynamic
0.9.5
```