示例#1
0
        // Used for protobuf json strings.
        public static byte[] Deflate <T>(string name, T data)
        {
            var jsonData          = Encoding.UTF8.GetBytes(name + ":" + CreateString(data) + "\0");
            var jsonDataLength    = BitConverter.GetBytes(jsonData.Length);
            var zlibHeader        = new byte[] { 0x78, 0x9C };
            var compressedData    = Zlib.Deflate(jsonData);
            var uncompressedAdler = BitConverter.GetBytes(Adler32.Calculate(jsonData)).Reverse().ToArray();

            return(jsonDataLength.Concat(zlibHeader).Concat(compressedData).Concat(uncompressedAdler).ToArray());
        }
示例#2
0
        public void DeflateRencode()
        {
            var list = "hello_world";

            string encode = Rencode.Encode(list);

            byte[] encodedBytes = encode.Select(Convert.ToByte).ToArray();

            byte[] bytes  = Zlib.Deflate(encodedBytes);
            string base64 = Base64.Encode(bytes);
        }
示例#3
0
 public byte[] Encode(byte[] bytes)
 {
     return(Zlib.Deflate(bytes));
 }