Ejemplo n.º 1
0
    public static void OnDataReceive(System.Object sender, DataEventArgs e)
    {
        print("buff length: " + e.Length + ", offset: " + e.Offset);

        if (e.Length <= 0)
        {
            return;
        }
//		CodedInputStream stream = CodedInputStream.CreateInstance(e.Data);
//		int length = (int)stream.ReadRawVarint32();
//		byte[] baseBytes = stream.ReadRawBytes (e.Length);
//		byte[] baseBytes = stream.ToArray();

        MemoryStream stream = new MemoryStream(e.Data);

        byte[] baseBytes = new byte[e.Length];
        stream.Read(baseBytes, e.Offset, e.Length);

        BasePacket basePacket = BasePacket.ParseFrom(baseBytes);
        int        packetId   = basePacket.PacketId;

        byte[]     namePacketBytes = basePacket.PacketData.ToByteArray();
        NamePacket response        = NamePacket.ParseFrom(namePacketBytes);

        print("packetId - " + packetId + ", response - " + response);
    }