Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protobuf - Missing toByteArray()?

I probably just messed up something in my proto file but I can't seem to call the toByteArray function.

Using Java and the proto file was compiled with protoc.

What I'm calling...

BaseMessage.builder = baseMessage = BaseMessage.newBuilder();
Acknowledgement.builder = acknowledgeMessage = Acknowledgement.newBuilder();

acknowledgeMessage.setOk(true);

baseMessage.setAcknowledgement(acknowledgeMessage);
baseMessage.build();

byte[] send = baseMessage.toByteArray();

And BaseMessage is declared as...

public static final class BaseMessage   
       extends com.google.protobuf.GeneratedMessage   
       implements BaseMessageOrBuilder {

Maybe I'm missing somthing...

BaseMessage is extending GeneratedMessage which inherits toByteArray() from AbstractMessageLite in which toByteArray is public... So I should be able to use it?

like image 217
Mytheral Avatar asked Aug 11 '14 01:08

Mytheral


1 Answers

Yes you are, you probably meant:

baseMessage.build().toByteArray()
like image 101
shlomi33 Avatar answered Sep 28 '22 05:09

shlomi33