Giter Club home page Giter Club logo

annotate-schemas's Introduction

annotate-schemas

This is an experimental repo on

  1. how to annotate binary schemas(protobuf) at field or message level [by using custom options]
  2. how to parse protobuf schemas [message and field-level attributes + options]

Pre-requisites

  1. Install protoc or buf(https://docs.buf.build/installation)

Approach 1

Parse proto source files directly using wire-schema API

Instructions

  1. Run WireParser.java

Positives

  1. Ability to directly parse the plain-text proto file
  2. Can extract comments also

Negatives

  1. Wire API's ProtoParser doesn't automatically load/merge imported schemas

Approach 2

Use protobuf API's FileDescriptorSet to parse protobuf file and its dependencies

Instructions

  1. Generate java bindings for proto file with definition of custom options

    protoc --proto_path=src/main/resources/proto --java_out=src/main/java  --experimental_allow_proto3_optional src/main/resources/proto/playground/options/v1/business_term_options.proto
    

    or

    buf generate --config '{"version":"v1beta1","build":{"roots":["src/main/resources/proto"]}}' --template '{"version":"v1beta1","plugins":[{"name":"java","out":"src/main/java"}]}' --path src/main/resources/proto/playground/options/v1/business_term_options.proto
    
  2. Compile protobuf files to generate a compiled binary descriptor file(contains a FileDescriptorSet (a protocol buffer, defined in descriptor.proto))

    protoc --proto_path=src/main/resources/proto --descriptor_set_out=src/main/resources/protoc-bin/message_sample.desc --include_imports src/main/resources/proto/playground/v1/message_sample.proto
    

    or

    buf build --config '{"version":"v1beta1","build":{"roots":["src/main/resources/proto"]}}' --exclude-source-info -o src/main/resources/buf-bin/message_sample.desc --path src/main/resources/proto/playground/v1/message_sample.proto
    
  3. Run DescriptorFileParser.java

Positives

  1. Parser automatically loads imported schemas

Negatives

  1. Extra pre-processing step: compile proto files into a descriptor file
  2. compile-time dependency of Java bindings for custom options (to populate extensionRegistry)
  3. Unable to parse comments

Other Approaches:

  1. Dymamically load java bindings
    • [Not considered] as it uses reflection
  2. Parse using Confluent-Kafka Schema Registry API (schema can be read from file or schema registry)
    • [Not considered] as
      1. doesn't support options
      2. it creates heavy coupling with confluent schema-registry

annotate-schemas's People

Contributors

shakti-garg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.