示例#1
0
            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);
            }
示例#2
0
            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());
            }
示例#3
0
        // ---------------------
        // ----- 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);
        }
示例#4
0
        public void Add(InternalPacket packet)
        {
            if (m_Eof)
            {
                return;
            }

            m_Packets.Enqueue(new PacketItem(packet));
            StartReader();
        }
示例#5
0
        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);
        }
示例#6
0
 public static byte[] Serialize(InternalPacket data)
 {
     return(ProtoSerialize(data));
 }
示例#7
0
 public PacketItem(InternalPacket packet)
 {
     this.Packet = packet;
 }
示例#8
0
 public static byte[] Serialize(InternalPacket data)
 {
     return(InternalPacket.InternalFactory.Serialize(data));
 }
示例#9
0
 public bool TrySend(InternalPacket packet)
 {
     return(m_transport.TrySend(packet));
 }
示例#10
0
 public void Send(InternalPacket packet)
 {
     m_transport.Send(packet);
 }
示例#11
0
 public static RpcException GetException(InternalPacket packet)
 {
     return(packet.Exception);
 }
示例#12
0
 public static TReceived GetData <TReceived>(InternalPacket packet, Marshaller <TReceived> marshaller)
 {
     return(marshaller.Deserializer(packet.Payload));
 }