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)); } }
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)); } }
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); } }
virtual public void Encode(WriteBuffer wb) { }
public static void PackDouble(WriteBuffer wb, double value) { wb.Add(0xcb, ReverseBytes(value)); }
public static void PackDouble(WriteBuffer wb, float value) { wb.Add(0xca, ReverseBytes(value)); }
public static void PackNil(WriteBuffer wb) { wb.Add(0xc0); }