我有Stream我需要通过 protobuf 消息作为bytes. 如何将 转换Stream为ByteStringprotobuf 所期望的?它是否像文档序列化中显示的那样简单?
由于项目的性质,我无法很好地测试它,所以我有点盲目工作。这是我正在使用的内容:
协议缓冲区:
message ProtoResponse {
bytes ResponseValue = 1;
}
Run Code Online (Sandbox Code Playgroud)
C#
public ProtoResponse SendResponse(Stream stream)
{
var response = ProtoResponse
{
// this obviously does not work but
// but it conveys the idea of what I am going for
ResponseValue = stream
}
return response;
}
Run Code Online (Sandbox Code Playgroud)
我试图将 转换Stream为 astring或 abyte[]但 VS 中的 C# 编译器不断显示此错误消息:
Cannot implicitly convert …