public static InternalPacket ProtoDeserialize(byte[] data, int pos, int size) { InternalPacket ret = new InternalPacket(); PacketProto protoPacket = new PacketProto(); MemoryStream ms = new MemoryStream(data, pos, size); protoPacket.MergeFrom(ms); ret.MsgId = protoPacket.MsgId; ret.FullMethodName = protoPacket.FullMethodName; ret.Options = protoPacket.Options; if (protoPacket.DataTypeCase == PacketProto.DataTypeOneofCase.Payload) { ret.Payload = protoPacket.Payload.Data.ToByteArray(); int payloadSize = protoPacket.Payload.Size; if (payloadSize < 0 || payloadSize > ms.Length || ret.Payload.Length != payloadSize) { throw new InvalidDataException("Pacote inválido: tamanho de payload inválido"); } } if (protoPacket.DataTypeCase == PacketProto.DataTypeOneofCase.Exception) { ret.Exception = RpcExceptionFactory.CreateFrom(protoPacket.Exception); } return(ret); }
public static byte [] ProtoSerialize(InternalPacket data) { PacketProto packet = new PacketProto(); packet.FullMethodName = data.FullMethodName ?? ""; packet.MsgId = data.MsgId; packet.Options = data.Options; if (data.Payload != null) { packet.Payload = new PayloadProto(); packet.Payload.Size = data.Payload.Length; packet.Payload.Data = ByteString.CopyFrom(data.Payload); } if (data.Exception != null) { packet.Exception = new RpcExceptionProto(); packet.Exception.StatusCode = (int)data.Exception.Status.StatusCode; packet.Exception.Detail = data.Exception.Status.Detail; if (data.Exception.Message == data.Exception.Status.ToString()) { packet.Exception.Message = ""; } else { packet.Exception.Message = data.Exception.Message; } } return(packet.ToByteArray()); }
// --------------------- // ----- INTERNALS ----- // --------------------- private static InternalPacket NewInternalPacket <TSend>(int msgId, int options, string fullName, Marshaller <TSend> marshaller, TSend request) { InternalPacket packet = InternalPacket.Create(); packet.MsgId = msgId; packet.FullMethodName = fullName ?? ""; packet.Options = options; packet.Payload = marshaller.Serializer(request); return(packet); }
public void Add(InternalPacket packet) { if (m_Eof) { return; } m_Packets.Enqueue(new PacketItem(packet)); StartReader(); }
private static InternalPacket NewInternalPacket(int msgId, int options, string fullName = null, RpcException exception = null) { InternalPacket packet = InternalPacket.Create(); packet.MsgId = msgId; packet.FullMethodName = fullName ?? ""; packet.Options = options; if (exception != null) { packet.Exception = exception; } return(packet); }
public static byte[] Serialize(InternalPacket data) { return(ProtoSerialize(data)); }
public PacketItem(InternalPacket packet) { this.Packet = packet; }
public static byte[] Serialize(InternalPacket data) { return(InternalPacket.InternalFactory.Serialize(data)); }
public bool TrySend(InternalPacket packet) { return(m_transport.TrySend(packet)); }
public void Send(InternalPacket packet) { m_transport.Send(packet); }
public static RpcException GetException(InternalPacket packet) { return(packet.Exception); }
public static TReceived GetData <TReceived>(InternalPacket packet, Marshaller <TReceived> marshaller) { return(marshaller.Deserializer(packet.Payload)); }