Mohan
Mohan

Reputation: 8853

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.

Upvotes: 0

Views: 686

Answers (1)

Kenton Varda
Kenton Varda

Reputation: 45246

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.

Upvotes: 1

Related Questions