开发者

Protobuf Nested Message Parsing Not working

开发者 https://www.devze.com 2023-02-13 02:10 出处:网络
I\'m trying to parse a protobuf message, but if I have nested messages, the parsing fails. The program sending the message is using dotnet-protobufs. When I call IsInitialized on the message it is fi

I'm trying to parse a protobuf message, but if I have nested messages, the parsing fails.

The program sending the message is using dotnet-protobufs. When I call IsInitialized on the message it is fine. When I view the ToString() version before I send it over the wire it looks correct.

When I get it on the client side (c++), the parsing fails. If I do ParsePartialFromString and then .DebugString() the nested messages aren't properly constructed. I get something like this:

command: NEW  
nested_message {  
  0: 0x727568541b121d0a  
  14 {  
  }  
}

I know it isn't a bas开发者_开发百科ic issue because when I do this from the same client and server with a non-nested message it works fine. It is something specific to the nesting.

I tried googling this but got no results. Any help?

Edit: This the the code doing the object creation. I call ToString() on the object and send it over the wire.

private Request createRequestString()
{
    Request.Types.ClientDetails clientDetails = Request.Types.ClientDetails.CreateBuilder()
         .SetClientTimestamp(DateTime.Now.ToLongDateString())
        .Build();

    Request.Types.Details details = Request.Types.Details.CreateBuilder()
        .SetType(Request.Types.Details.Types.Types.NORMAL)
        .SetCurrency("CND")
        .SetDate(DateTime.Now.ToLongDateString())
        .Build();

    Request.Types.NewRequest newrequest = Request.Types.NewRequest.CreateBuilder()
        .SetClientDetails(clientDetails)
        .SetDetails(details)
        .Build();

    Request request = Request.CreateBuilder()
        .SetCommand(Request.Types.Commands.NEW)
        .SetNewRequest(newrequest)                
        .Build();

    bool isClientGood = clientDetails.IsInitialized;
    bool isDetailGood = details.IsInitialized;
    bool isNewRequestGood = newrequest.IsInitialized;
    bool isAllGood = request.IsInitialized;
    return request;         
}

0

精彩评论

暂无评论...
验证码 换一张
取 消