简体   繁体   中英

Google protobuf generated Java does not support toByteArray

I have used protoc to generate Java source from

https://github.com/mapbox/vector-tile-spec/blob/master/2.1/vector_tile.proto

The protobuf documentation suggests that the resulting class should support a toByteArray method. It doesn't. (As well as trying to call it, I have searched the generated file VectorTile.java and there is no toByteArray code in there.)

NB. this is not a duplicate of Protobuf - Missing toByteArray()? -- the error there is using a Builder where a Message is intended. I'm not doing that.

I'd be grateful for any insights.

The toByteArray() method is implemented in AbstractMessageLite , which the generated code inherits. There isn't a declaration of toByteArray() in the generated code because it is inherited. Calling message.toByteArray() will work fine -- if it isn't working for you, please show your code and the error message produced.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM