criccomini / proto-schema-parser

A Pure Python Protobuf Parser
MIT License
38 stars 20 forks source link

Add ProtobufGenerator to write `ast.File` objects as Proto strings #7

Closed criccomini closed 1 year ago

criccomini commented 1 year ago

proto-schema-parser can now seralize Protobuf represented as ast.File objects back into Protobuf schema strings.

The ProtobufGenerator class will converter:

ast.Message(
    name="MyMessage",
    elements=[
        ast.Field(
            name="my_field",
            type="string",
            number=1,
            cardinality=ast.FieldCardinality.OPTIONAL,
        ),
        ast.Field(
            name="another_field",
            type="int32",
            number=2,
            cardinality=ast.FieldCardinality.REQUIRED,
        ),
    ],
)

To:

message MyMessage {
  optional string my_field = 1;
  required int32 another_field = 2;
"