Skip to content

Protocol Buffers Dynamic Schema - create protobuf schemas programmatically

License

Notifications You must be signed in to change notification settings

jhsenjaliya/protobuf-dynamic

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

protobuf-dynamic

Protocol Buffers Dynamic Schema - create protobuf schemas programmatically. Available on Maven Central:

Maven Central Maven Central


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

// 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"), "[email protected]")
		.build();

Maven dependency

<dependency>
  <groupId>com.github.os72</groupId>
  <artifactId>protobuf-dynamic</artifactId>
  <version>1.0.0</version>
</dependency>

About

Protocol Buffers Dynamic Schema - create protobuf schemas programmatically

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%