本文介绍了Protobuf - 缺少toByteArray()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能只是在我的proto文件中弄乱了一些东西,但我似乎无法调用toByteArray函数。

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

使用Java和原型文件是用protoc编译的。

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();

并且BaseMessage被声明为......

And BaseMessage is declared as...

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

也许我错过了什么...

Maybe I'm missing somthing...

BaseMessage正在扩展从,其中toByteArray是公开的......所以我应该可以使用吗?

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

推荐答案

是的,你可能意味着:

baseMessage.build().toByteArray()

这篇关于Protobuf - 缺少toByteArray()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 19:44