API to find out which protobuf message is sent to

What is an API to find out which protobuf message is being sent?

For example, I use the following to get a SendNameMessage object.

SendNameMessage sendNameObj = Serializer.DeserializeWithLengthPrefix <SendNameMessage> (stream, PrefixStyle.Fixed32);

How does the listener know which message is being sent?

Below is my SendNameMessage class:

[ProtoContract]
class SendNameMessage
{
    [ProtoMember(1)]
    public string sendName { get; set; }

    [ProtoMember(2)]
    public int sendId { get; set; }
}

How do I know if a send message is sent sendName or sendId?

+3
source share
1 answer

protobuf ( ) - API- . , , . :

  • -, . protobuf-net ( protobuf-net )
  • - - , . , Base128, , ( 1, ). Serializer.NonGeneric.TryDeserializeWithLengthPrefix, .

... sendId sendName, SendNameMessage. ( ). , . . , .sendName .sendId.

, , :

enum MesageType {
    Error = 0,
    Name = 1,
    Id = 2
}

:

[ProtoMember(10)]
public MessageType MessageType {get;set;}

.

+3

Source: https://habr.com/ru/post/1754272/


All Articles