Beispiel #1
0
    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);
    }
Beispiel #2
0
    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);
    }
Beispiel #3
0
    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);
    }