コード例 #1
0
    public static msg_cmd Decode_Json(byte[] package)
    {
        msg_cmd cmd = new msg_cmd();

        cmd.stype = package[0] | (package[1] << 8);
        cmd.ctype = package[2] | (package[3] << 8);
        cmd.body  = new byte[package.Length - 8];
        BytesWriter.Write_Byte_to_bytes(package, 8, cmd.body, 0);
        return(cmd);
    }
コード例 #2
0
ファイル: TcpPacker.cs プロジェクト: iLOVECris/CarWar
    public static byte[] Package(byte[] data)
    {
        int header_len = 2;
        int data_len   = data.Length + header_len;

        if (data.Length > 65535 - 2)
        {
            return(null);
        }
        byte[] package = new byte[data_len];
        BytesWriter.Write_short_to_bytes(package, 0, (short)data_len);
        BytesWriter.Write_Byte_to_bytes(data, 0, package, 2);
        return(package);
    }
コード例 #3
0
ファイル: EncodeCmd.cs プロジェクト: iLOVECris/CarWar
    public static byte[] Encode_Json(int stype, int ctype, string json_str)
    {
        int Header_Len = 8;

        byte[] byte_array = null;
        if (json_str != null)
        {
            byte_array = System.Text.Encoding.UTF8.GetBytes(json_str);
        }
        byte[] Encode_Bytes = new byte[Header_Len + byte_array.Length];
        BytesWriter.Write_short_to_bytes(Encode_Bytes, 0, (short)stype);
        BytesWriter.Write_short_to_bytes(Encode_Bytes, 2, (short)ctype);
        BytesWriter.Write_Byte_to_bytes(byte_array, 0, Encode_Bytes, 8);
        return(Encode_Bytes);
    }
コード例 #4
0
ファイル: TcpPacker.cs プロジェクト: iLOVECris/CarWar
 public static byte[] UnPackage(byte[] data, out int header_len)
 {
     if (data.Length < 2)
     {
         header_len = 0;
         return(null);
     }
     header_len = data[0] | data[1] << 8;
     if (header_len > data.Length)//接收的数据不足
     {
         return(null);
     }
     byte[] package = new byte[header_len - 2];
     BytesWriter.Write_Byte_to_bytes(data, 2, package, 0);
     return(package);
 }
コード例 #5
0
ファイル: EncodeCmd.cs プロジェクト: iLOVECris/CarWar
    public static byte[] Encode_Protobuf(int stype, int ctype, ProtoBuf.IExtensible body)
    {
        int Header_Len = 8;

        byte[] byte_array = null;
        int    body_len   = 0;

        if (body != null)
        {
            byte_array = Serialize(body);
            body_len   = byte_array.Length;
        }
        byte[] Encode_Bytes = new byte[Header_Len + body_len];
        BytesWriter.Write_short_to_bytes(Encode_Bytes, 0, (short)stype);
        BytesWriter.Write_short_to_bytes(Encode_Bytes, 2, (short)ctype);
        if (body != null)
        {
            BytesWriter.Write_Byte_to_bytes(byte_array, 0, Encode_Bytes, 8);
        }
        return(Encode_Bytes);
    }
コード例 #6
0
        void Start()
        {
            var writer = new BytesWriter();

            writer.WriteInt(90);
            writer.WriteString("Vatsal");
            writer.WriteString("Adrenak");
            writer.WriteString("Ambastha");
            writer.WriteVector3(Vector3.one);
            writer.WriteFloatArray(new[] { 1.1f, 2.2f, 3.3f });

            var reader = new BytesReader(writer.Bytes);

            // READ IN THE SAME ORDER
            Debug.Log(reader.ReadInt());
            Debug.Log(reader.ReadString());
            Debug.Log(reader.ReadString());
            Debug.Log(reader.ReadString());
            Debug.Log(reader.ReadVector3());
            Debug.Log("Floats : " + string.Join(", ", reader.ReadFloatArray()));
        }
コード例 #7
0
 public BytesPipe(IBytesPool bytesPool)
 {
     _state  = new BytesState(bytesPool);
     _reader = new BytesReader(_state);
     _writer = new BytesWriter(_state);
 }