I suggest using protobuf-netfor serialization DTO.
So, define some object, for example Package( CommandMessagein your example), which has
public Command Command;
public byte[] Data;(serialized from protobuf)
Based on, Commandyou can deserialize Datafor a specific type DTOusing protobuf.
, Package.
, Package / / ( ).
e.g package.WriteTo(buffer) [BB,Command,Data,B8]. package.ReadFrom()