Ejemplo n.º 1
0
    public static ByteBuf NewPacket(pb.ID id, Google.ProtocolBuffers.IMessage msg = null)
    {
        var bufLen = BitConverter.GetBytes((ushort)0);


        var t = new List <byte>();

        byte[] buffData = null;
        if (null != msg)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                //Save the person to a stream
                msg.WriteTo(stream);
                buffData = stream.ToArray();

                bufLen = BitConverter.GetBytes((ushort)buffData.Length);
            }
        }

        if (BitConverter.IsLittleEndian)
        {
            Array.Reverse(bufLen);
        }
        t.AddRange(bufLen);
        t.Add((byte)id);
        if (null != buffData)
        {
            t.AddRange(buffData);
        }

        return(new ByteBuf(t.ToArray()));
    }
Ejemplo n.º 2
0
 public void Send(pb.ID id, Google.ProtocolBuffers.IMessage obj = null)
 {
     if (null != client && client.IsRunning() && Connected)
     {
         client.Send(PacketWraper.NewPacket(id, obj));
     }
     else
     {
         UnityEngine.Debug.LogError("client no connect");
     }
 }