小编kos*_*shi的帖子

将 Stream 转换为 ByteString

我有Stream我需要通过 protobuf 消息作为bytes. 如何将 转换StreamByteStringprotobuf 所期望的?它是否像文档序列化中显示的那样简单?

由于项目的性质,我无法很好地测试它,所以我有点盲目工作。这是我正在使用的内容:

协议缓冲区:

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 …

.net c# protocol-buffers proto grpc

5
推荐指数
1
解决办法
3756
查看次数

标签 统计

.net ×1

c# ×1

grpc ×1

proto ×1

protocol-buffers ×1