FasterXML / jackson-dataformats-binary

Uber-project for standard Jackson binary format backends: avro, cbor, ion, protobuf, smile
Apache License 2.0
311 stars 135 forks source link

[protobuf] can't parse `reserved` field #84

Open knoguchi opened 7 years ago

knoguchi commented 7 years ago

This is a Protoparser problem that it failed to parse reserved field.

Reserved field is explained in the official document. https://developers.google.com/protocol-buffers/docs/proto#reserved

va.lang.IllegalStateException: Syntax error in Unnamed-protobuf-schema at 389:11: unexpected label: reserved

    at com.squareup.protoparser.ProtoParser.unexpected(ProtoParser.java:948)
    at com.squareup.protoparser.ProtoParser.readDeclaration(ProtoParser.java:197)
    at com.squareup.protoparser.ProtoParser.readMessage(ProtoParser.java:219)
    at com.squareup.protoparser.ProtoParser.readDeclaration(ProtoParser.java:153)
    at com.squareup.protoparser.ProtoParser.readProtoFile(ProtoParser.java:92)
    at com.squareup.protoparser.ProtoParser.parse(ProtoParser.java:61)
    at com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchemaLoader._loadNative(ProtobufSchemaLoader.java:167)
    at com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchemaLoader._loadNative(ProtobufSchemaLoader.java:161)
    at com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchemaLoader.loadNative(ProtobufSchemaLoader.java:135)
    at com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchemaLoader.load(ProtobufSchemaLoader.java:80)
cowtowncoder commented 7 years ago

Do you know if this is a new addition to particular version of protobuf specification?

knoguchi commented 7 years ago

I did a bit of research. It seems reserved was added when protobuf v3.0.0-beta was released 2 years ago for both proto2 and proto3 syntax.

The protoc-2.6.1 can't parse the syntax. So it's only available in the protobuf v3.x.x releases. It's a bit confusing but the release version and syntax version is not necessarily corresponding . The proto2 syntax is maintained in the v3 releases.


For now I just commented out the reserved fields. So this is not a big issue.

cowtowncoder commented 7 years ago

Ok thank you for checking this out. I was just trying to figure this out since I did not remember seeing this keyword before myself. It seems like a useful thing to have, of course, even with proto v2 as it does not change encoding format. And it is useful for general schema management.