Exemplo n.º 1
0
        public static void PackMap(WriteBuffer wb, long length)
        {
            byte topbyte;

            // map fixmap, 16,32 : 0x80|num, 0xde+2byte, 0xdf+4byte
            if (length < 16)
            {
                topbyte = (byte)(0x80 | (byte)length);
                wb.Add(topbyte);
            }
            else if (length < 65536)
            {
                topbyte = 0xde;
                wb.Add(topbyte, ReverseBytes((ushort)length));
            }
            else if (length < 4294967296 - 1)
            {
                topbyte = 0xdf;
                wb.Add(topbyte, ReverseBytes((uint)length));
            }
        }
Exemplo n.º 2
0
        public static void PackArray(WriteBuffer wb, long length)
        {
            byte topbyte;

            // array!(ignore map part.) 0x90|n , 0xdc+2byte, 0xdd+4byte
            if (length < 16)
            {
                topbyte = (byte)(0x90 | (byte)length);
                wb.Add(topbyte);
            }
            else if (length < 65536)
            {
                topbyte = 0xdc;
                wb.Add(topbyte, ReverseBytes((ushort)length));
            }
            else if (length < 4294967296 - 1)  // TODO: avoid C warn
            {
                topbyte = 0xdd;
                wb.Add(topbyte, ReverseBytes((uint)length));
            }
        }
Exemplo n.º 3
0
        public static void PackString(WriteBuffer wb, string str)
        {
            if (str == null)
            {
                PackNil(wb);
                return;
            }
            long slen    = str.Length;
            byte topbyte = 0;

            if (slen < 32)
            {
                topbyte = (byte)(0xa0 | (byte)slen);
                wb.Add(topbyte, Eproto.StringToBytes(str));
            }
            else if (slen < 256)
            {
                topbyte = 0xd9;
                wb.Add(topbyte, ReverseBytes((byte)slen), Eproto.StringToBytes(str));
            }
            else if (slen < 65536)
            {
                topbyte = 0xda;
                wb.Add(topbyte, ReverseBytes((ushort)slen), Eproto.StringToBytes(str));
            }
            else if (slen < 4294967296 - 1)  // TODO: -1 for avoiding (condition is always true warning)
            {
                topbyte = 0xdb;
                wb.Add(topbyte, ReverseBytes((uint)slen), Eproto.StringToBytes(str));
            }
            else
            {
                PackNil(wb);
                Console.WriteLine("PackString length is out of uint " + slen);
            }
        }
Exemplo n.º 4
0
 virtual public void Encode(WriteBuffer wb)
 {
 }
Exemplo n.º 5
0
 public static void PackDouble(WriteBuffer wb, double value)
 {
     wb.Add(0xcb, ReverseBytes(value));
 }
Exemplo n.º 6
0
 public static void PackDouble(WriteBuffer wb, float value)
 {
     wb.Add(0xca, ReverseBytes(value));
 }
Exemplo n.º 7
0
 public static void PackNil(WriteBuffer wb)
 {
     wb.Add(0xc0);
 }