예제 #1
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);
            }
        }
예제 #2
0
 public string CopyString(int count)
 {
     byte[] b = CopyBytes(count);
     return(Eproto.BytesToString(b));
 }