Ejemplo n.º 1
0
 public void SetAsBytes(byte[] value)
 {
     this.innerValue = value;
     this.valueType = MsgPackType.Binary;
 }
Ejemplo n.º 2
0
 public void SetAsInteger(Int64 value)
 {
     this.innerValue = value;
     this.valueType = MsgPackType.Integer;
 }
Ejemplo n.º 3
0
 public void SetAsUInt64(UInt64 value)
 {
     this.innerValue = value;
     this.valueType = MsgPackType.UInt64;
 }
Ejemplo n.º 4
0
 private void WriteType(MsgPackType token)
 {
     this.buffer[0] = (byte)token;
     this.outputStream.Write(this.buffer, 0, 1);
     this.bytesWritten++;
 }
Ejemplo n.º 5
0
 private MsgPack InnerAddArrayChild()
 {
     if (valueType != MsgPackType.Array)
     {
         Clear();
         this.valueType = MsgPackType.Array;
     }
     return InnerAdd();
 }
Ejemplo n.º 6
0
 public void SetAsBoolean(Boolean bVal)
 {
     this.valueType = MsgPackType.Boolean;
     this.innerValue = bVal;
 }
Ejemplo n.º 7
0
 public void SetAsFloat(Double fVal)
 {
     this.valueType = MsgPackType.Float;
     this.innerValue = fVal;
 }
Ejemplo n.º 8
0
 public void SetAsNull()
 {
     Clear();
     this.innerValue = null;
     this.valueType  = MsgPackType.Null;
 }
Ejemplo n.º 9
0
 public void SetAsString(String value)
 {
     this.innerValue = value;
     this.valueType  = MsgPackType.String;
 }
Ejemplo n.º 10
0
 public void SetAsUInt64(UInt64 value)
 {
     this.innerValue = value;
     this.valueType  = MsgPackType.UInt64;
 }
Ejemplo n.º 11
0
 public void SetAsBytes(byte[] value)
 {
     this.innerValue = value;
     this.valueType  = MsgPackType.Binary;
 }
Ejemplo n.º 12
0
 public void SetAsInteger(Int64 value)
 {
     this.innerValue = value;
     this.valueType  = MsgPackType.Integer;
 }
Ejemplo n.º 13
0
        public void DecodeFromStream(Stream ms)
        {
            byte lvByte = (byte)ms.ReadByte();

            byte[]  rawByte = null;
            MsgPack msgPack = null;
            int     len     = 0;
            int     i       = 0;

            if (lvByte <= 0x7F)
            {   //positive fixint	0xxxxxxx	0x00 - 0x7f
                SetAsInteger(lvByte);
            }
            else if ((lvByte >= 0x80) && (lvByte <= 0x8F))
            {
                //fixmap	1000xxxx	0x80 - 0x8f
                this.Clear();
                this.valueType = MsgPackType.Map;
                len            = lvByte - 0x80;
                for (i = 0; i < len; i++)
                {
                    msgPack = InnerAdd();
                    msgPack.SetName(ReadTools.ReadString(ms));
                    msgPack.DecodeFromStream(ms);
                }
            }
            else if ((lvByte >= 0x90) && (lvByte <= 0x9F))  //fixarray	1001xxxx	0x90 - 0x9f
            {
                //fixmap	1000xxxx	0x80 - 0x8f
                this.Clear();
                this.valueType = MsgPackType.Array;
                len            = lvByte - 0x90;
                for (i = 0; i < len; i++)
                {
                    msgPack = InnerAdd();
                    msgPack.DecodeFromStream(ms);
                }
            }
            else if ((lvByte >= 0xA0) && (lvByte <= 0xBF))  // fixstr	101xxxxx	0xa0 - 0xbf
            {
                len = lvByte - 0xA0;
                SetAsString(ReadTools.ReadString(ms, len));
            }
            else if ((lvByte >= 0xE0) && (lvByte <= 0xFF))
            {   /// -1..-32
                //  negative fixnum stores 5-bit negative integer
                //  +--------+
                //  |111YYYYY|
                //  +--------+
                SetAsInteger((sbyte)lvByte);
            }
            else if (lvByte == 0xC0)
            {
                SetAsNull();
            }
            else if (lvByte == 0xC1)
            {
                throw new Exception("(never used) type $c1");
            }
            else if (lvByte == 0xC2)
            {
                SetAsBoolean(false);
            }
            else if (lvByte == 0xC3)
            {
                SetAsBoolean(true);
            }
            else if (lvByte == 0xC4)
            {  // max 255
                len     = ms.ReadByte();
                rawByte = new byte[len];
                ms.Read(rawByte, 0, len);
                SetAsBytes(rawByte);
            }
            else if (lvByte == 0xC5)
            {  // max 65535
                rawByte = new byte[2];
                ms.Read(rawByte, 0, 2);
                rawByte = BytesTools.SwapBytes(rawByte);
                len     = BitConverter.ToUInt16(rawByte, 0);

                // read binary
                rawByte = new byte[len];
                ms.Read(rawByte, 0, len);
                SetAsBytes(rawByte);
            }
            else if (lvByte == 0xC6)
            {  // binary max: 2^32-1
                rawByte = new byte[4];
                ms.Read(rawByte, 0, 4);
                rawByte = BytesTools.SwapBytes(rawByte);
                len     = BitConverter.ToInt32(rawByte, 0);

                // read binary
                rawByte = new byte[len];
                ms.Read(rawByte, 0, len);
                SetAsBytes(rawByte);
            }
            else if ((lvByte == 0xC7) || (lvByte == 0xC8) || (lvByte == 0xC9))
            {
                throw new Exception("(ext8,ext16,ex32) type $c7,$c8,$c9");
            }
            else if (lvByte == 0xCA)
            {  // float 32
                rawByte = new byte[4];
                ms.Read(rawByte, 0, 4);
                rawByte = BytesTools.SwapBytes(rawByte);

                SetAsSingle(BitConverter.ToSingle(rawByte, 0));
            }
            else if (lvByte == 0xCB)
            {  // float 64
                rawByte = new byte[8];
                ms.Read(rawByte, 0, 8);
                rawByte = BytesTools.SwapBytes(rawByte);
                SetAsFloat(BitConverter.ToDouble(rawByte, 0));
            }
            else if (lvByte == 0xCC)
            {  // uint8
                //      uint 8 stores a 8-bit unsigned integer
                //      +--------+--------+
                //      |  0xcc  |ZZZZZZZZ|
                //      +--------+--------+
                lvByte = (byte)ms.ReadByte();
                SetAsInteger(lvByte);
            }
            else if (lvByte == 0xCD)
            {  // uint16
                //    uint 16 stores a 16-bit big-endian unsigned integer
                //    +--------+--------+--------+
                //    |  0xcd  |ZZZZZZZZ|ZZZZZZZZ|
                //    +--------+--------+--------+
                rawByte = new byte[2];
                ms.Read(rawByte, 0, 2);
                rawByte = BytesTools.SwapBytes(rawByte);
                SetAsInteger(BitConverter.ToUInt16(rawByte, 0));
            }
            else if (lvByte == 0xCE)
            {
                //  uint 32 stores a 32-bit big-endian unsigned integer
                //  +--------+--------+--------+--------+--------+
                //  |  0xce  |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ
                //  +--------+--------+--------+--------+--------+
                rawByte = new byte[4];
                ms.Read(rawByte, 0, 4);
                rawByte = BytesTools.SwapBytes(rawByte);
                SetAsInteger(BitConverter.ToUInt32(rawByte, 0));
            }
            else if (lvByte == 0xCF)
            {
                //  uint 64 stores a 64-bit big-endian unsigned integer
                //  +--------+--------+--------+--------+--------+--------+--------+--------+--------+
                //  |  0xcf  |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|
                //  +--------+--------+--------+--------+--------+--------+--------+--------+--------+
                rawByte = new byte[8];
                ms.Read(rawByte, 0, 8);
                rawByte = BytesTools.SwapBytes(rawByte);
                SetAsUInt64(BitConverter.ToUInt64(rawByte, 0));
            }
            else if (lvByte == 0xDC)
            {
                //      +--------+--------+--------+~~~~~~~~~~~~~~~~~+
                //      |  0xdc  |YYYYYYYY|YYYYYYYY|    N objects    |
                //      +--------+--------+--------+~~~~~~~~~~~~~~~~~+
                rawByte = new byte[2];
                ms.Read(rawByte, 0, 2);
                rawByte = BytesTools.SwapBytes(rawByte);
                len     = BitConverter.ToInt16(rawByte, 0);

                this.Clear();
                this.valueType = MsgPackType.Array;
                for (i = 0; i < len; i++)
                {
                    msgPack = InnerAdd();
                    msgPack.DecodeFromStream(ms);
                }
            }
            else if (lvByte == 0xDD)
            {
                //  +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
                //  |  0xdd  |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|    N objects    |
                //  +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
                rawByte = new byte[4];
                ms.Read(rawByte, 0, 4);
                rawByte = BytesTools.SwapBytes(rawByte);
                len     = BitConverter.ToInt16(rawByte, 0);

                this.Clear();
                this.valueType = MsgPackType.Array;
                for (i = 0; i < len; i++)
                {
                    msgPack = InnerAdd();
                    msgPack.DecodeFromStream(ms);
                }
            }
            else if (lvByte == 0xD9)
            {
                //  str 8 stores a byte array whose length is upto (2^8)-1 bytes:
                //  +--------+--------+========+
                //  |  0xd9  |YYYYYYYY|  data  |
                //  +--------+--------+========+
                SetAsString(ReadTools.ReadString(lvByte, ms));
            }
            else if (lvByte == 0xDE)
            {
                //    +--------+--------+--------+~~~~~~~~~~~~~~~~~+
                //    |  0xde  |YYYYYYYY|YYYYYYYY|   N*2 objects   |
                //    +--------+--------+--------+~~~~~~~~~~~~~~~~~+
                rawByte = new byte[2];
                ms.Read(rawByte, 0, 2);
                rawByte = BytesTools.SwapBytes(rawByte);
                len     = BitConverter.ToInt16(rawByte, 0);

                this.Clear();
                this.valueType = MsgPackType.Map;
                for (i = 0; i < len; i++)
                {
                    msgPack = InnerAdd();
                    msgPack.SetName(ReadTools.ReadString(ms));
                    msgPack.DecodeFromStream(ms);
                }
            }
            else if (lvByte == 0xDE)
            {
                //    +--------+--------+--------+~~~~~~~~~~~~~~~~~+
                //    |  0xde  |YYYYYYYY|YYYYYYYY|   N*2 objects   |
                //    +--------+--------+--------+~~~~~~~~~~~~~~~~~+
                rawByte = new byte[2];
                ms.Read(rawByte, 0, 2);
                rawByte = BytesTools.SwapBytes(rawByte);
                len     = BitConverter.ToInt16(rawByte, 0);

                this.Clear();
                this.valueType = MsgPackType.Map;
                for (i = 0; i < len; i++)
                {
                    msgPack = InnerAdd();
                    msgPack.SetName(ReadTools.ReadString(ms));
                    msgPack.DecodeFromStream(ms);
                }
            }
            else if (lvByte == 0xDF)
            {
                //    +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
                //    |  0xdf  |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|   N*2 objects   |
                //    +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
                rawByte = new byte[4];
                ms.Read(rawByte, 0, 4);
                rawByte = BytesTools.SwapBytes(rawByte);
                len     = BitConverter.ToInt32(rawByte, 0);

                this.Clear();
                this.valueType = MsgPackType.Map;
                for (i = 0; i < len; i++)
                {
                    msgPack = InnerAdd();
                    msgPack.SetName(ReadTools.ReadString(ms));
                    msgPack.DecodeFromStream(ms);
                }
            }
            else if (lvByte == 0xDA)
            {
                //      str 16 stores a byte array whose length is upto (2^16)-1 bytes:
                //      +--------+--------+--------+========+
                //      |  0xda  |ZZZZZZZZ|ZZZZZZZZ|  data  |
                //      +--------+--------+--------+========+
                SetAsString(ReadTools.ReadString(lvByte, ms));
            }
            else if (lvByte == 0xDB)
            {
                //  str 32 stores a byte array whose length is upto (2^32)-1 bytes:
                //  +--------+--------+--------+--------+--------+========+
                //  |  0xdb  |AAAAAAAA|AAAAAAAA|AAAAAAAA|AAAAAAAA|  data  |
                //  +--------+--------+--------+--------+--------+========+
                SetAsString(ReadTools.ReadString(lvByte, ms));
            }
            else if (lvByte == 0xD0)
            {
                //      int 8 stores a 8-bit signed integer
                //      +--------+--------+
                //      |  0xd0  |ZZZZZZZZ|
                //      +--------+--------+
                SetAsInteger((sbyte)ms.ReadByte());
            }
            else if (lvByte == 0xD1)
            {
                //    int 16 stores a 16-bit big-endian signed integer
                //    +--------+--------+--------+
                //    |  0xd1  |ZZZZZZZZ|ZZZZZZZZ|
                //    +--------+--------+--------+
                rawByte = new byte[2];
                ms.Read(rawByte, 0, 2);
                rawByte = BytesTools.SwapBytes(rawByte);
                SetAsInteger(BitConverter.ToInt16(rawByte, 0));
            }
            else if (lvByte == 0xD2)
            {
                //  int 32 stores a 32-bit big-endian signed integer
                //  +--------+--------+--------+--------+--------+
                //  |  0xd2  |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|
                //  +--------+--------+--------+--------+--------+
                rawByte = new byte[4];
                ms.Read(rawByte, 0, 4);
                rawByte = BytesTools.SwapBytes(rawByte);
                SetAsInteger(BitConverter.ToInt32(rawByte, 0));
            }
            else if (lvByte == 0xD3)
            {
                //  int 64 stores a 64-bit big-endian signed integer
                //  +--------+--------+--------+--------+--------+--------+--------+--------+--------+
                //  |  0xd3  |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|
                //  +--------+--------+--------+--------+--------+--------+--------+--------+--------+
                rawByte = new byte[8];
                ms.Read(rawByte, 0, 8);
                rawByte = BytesTools.SwapBytes(rawByte);
                SetAsInteger(BitConverter.ToInt64(rawByte, 0));
            }
        }
Ejemplo n.º 14
0
 public void SetAsFloat(Double fVal)
 {
     this.valueType  = MsgPackType.Float;
     this.innerValue = fVal;
 }
Ejemplo n.º 15
0
 public void SetAsNull()
 {
     Clear();
     this.innerValue = null;
     this.valueType = MsgPackType.Null;
 }
Ejemplo n.º 16
0
 public void SetAsBoolean(Boolean bVal)
 {
     this.valueType  = MsgPackType.Boolean;
     this.innerValue = bVal;
 }
Ejemplo n.º 17
0
 public void SetAsString(String value)
 {
     this.innerValue = value;
     this.valueType = MsgPackType.String;
 }
Ejemplo n.º 18
0
 public void SetAsSingle(Single fVal)
 {
     this.valueType  = MsgPackType.Single;
     this.innerValue = fVal;
 }
Ejemplo n.º 19
0
 public void SetAsSingle(Single fVal)
 {
     this.valueType = MsgPackType.Single;
     this.innerValue = fVal;
 }
Ejemplo n.º 20
0
 private MsgPack InnerAddMapChild()
 {
     if (valueType!=MsgPackType.Map)
     {
         Clear();
         this.valueType = MsgPackType.Map;
     }
     return InnerAdd();
 }
Ejemplo n.º 21
0
        public void DecodeFromStream(Stream ms)
        {            
            byte lvByte  = (byte)ms.ReadByte();
            byte[] rawByte = null;
            MsgPack msgPack = null;
            int len = 0;
            int i = 0;
            
            if (lvByte <= 0x7F)
            {   //positive fixint	0xxxxxxx	0x00 - 0x7f
                SetAsInteger(lvByte);
            }else if ((lvByte >= 0x80) && (lvByte <= 0x8F))
            {
                //fixmap	1000xxxx	0x80 - 0x8f
                this.Clear();
                this.valueType = MsgPackType.Map;
                len = lvByte - 0x80;
                for (i=0; i<len;i++)
                {
                    msgPack = InnerAdd();
                    msgPack.SetName(ReadTools.ReadString(ms));                    
                    msgPack.DecodeFromStream(ms);
                }
            }
            else if ((lvByte >= 0x90) && (lvByte <= 0x9F))  //fixarray	1001xxxx	0x90 - 0x9f
            {
                //fixmap	1000xxxx	0x80 - 0x8f
                this.Clear();
                this.valueType = MsgPackType.Array;
                len = lvByte - 0x90;
                for (i = 0; i < len; i++)
                {
                    msgPack = InnerAdd();
                    msgPack.DecodeFromStream(ms);
                }
            }
            else if ((lvByte >= 0xA0) && (lvByte <= 0xBF))  // fixstr	101xxxxx	0xa0 - 0xbf
            {
                len = lvByte - 0xA0;
                SetAsString(ReadTools.ReadString(ms, len));
            }
            else if ((lvByte >= 0xE0) && (lvByte <= 0xFF))
            {   /// -1..-32
                //  negative fixnum stores 5-bit negative integer
                //  +--------+
                //  |111YYYYY|
                //  +--------+                
                SetAsInteger((sbyte)lvByte);
            }
            else if (lvByte == 0xC0)
            {
                SetAsNull();
            }
            else if (lvByte == 0xC1)
            {
                throw new Exception("(never used) type $c1");
            }
            else if (lvByte == 0xC2)
            {
                SetAsBoolean(false);
            }
            else if (lvByte == 0xC3)
            {
                SetAsBoolean(true);
            }
            else if (lvByte == 0xC4)
            {  // max 255
                len = ms.ReadByte();
                rawByte = new byte[len];
                ms.Read(rawByte, 0, len);
                SetAsBytes(rawByte);
            }
            else if (lvByte == 0xC5)
            {  // max 65535                
                rawByte = new byte[2];
                ms.Read(rawByte, 0, 2);
                rawByte = BytesTools.SwapBytes(rawByte);
                len = BitConverter.ToInt16(rawByte, 0);

                // read binary
                rawByte = new byte[len];
                ms.Read(rawByte, 0, len);
                SetAsBytes(rawByte);
            }
            else if (lvByte == 0xC6)
            {  // binary max: 2^32-1                
                rawByte = new byte[4];
                ms.Read(rawByte, 0, 4);
                rawByte = BytesTools.SwapBytes(rawByte);
                len = BitConverter.ToInt32(rawByte, 0);

                // read binary
                rawByte = new byte[len];
                ms.Read(rawByte, 0, len);
                SetAsBytes(rawByte);
            }
            else if ((lvByte == 0xC7) || (lvByte == 0xC8) || (lvByte == 0xC9))
            {
                throw new Exception("(ext8,ext16,ex32) type $c7,$c8,$c9");
            }
            else if (lvByte == 0xCA)
            {  // float 32              
                rawByte = new byte[4];
                ms.Read(rawByte, 0, 4);
                rawByte = BytesTools.SwapBytes(rawByte);
                
                SetAsSingle(BitConverter.ToSingle(rawByte, 0));
            }
            else if (lvByte == 0xCB)
            {  // float 64              
                rawByte = new byte[8];
                ms.Read(rawByte, 0, 8);
                rawByte = BytesTools.SwapBytes(rawByte);
                SetAsFloat(BitConverter.ToDouble(rawByte, 0));
            }
            else if (lvByte == 0xCC)
            {  // uint8   
                //      uint 8 stores a 8-bit unsigned integer
                //      +--------+--------+
                //      |  0xcc  |ZZZZZZZZ|
                //      +--------+--------+
                lvByte =(byte)ms.ReadByte();
                SetAsInteger(lvByte);
            }
            else if (lvByte == 0xCD)
            {  // uint16      
                //    uint 16 stores a 16-bit big-endian unsigned integer
                //    +--------+--------+--------+
                //    |  0xcd  |ZZZZZZZZ|ZZZZZZZZ|
                //    +--------+--------+--------+
                rawByte = new byte[2];
                ms.Read(rawByte, 0, 2);
                rawByte = BytesTools.SwapBytes(rawByte);
                SetAsInteger(BitConverter.ToUInt16(rawByte, 0));
            }
            else if (lvByte == 0xCE)
            {      
                //  uint 32 stores a 32-bit big-endian unsigned integer
                //  +--------+--------+--------+--------+--------+
                //  |  0xce  |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ
                //  +--------+--------+--------+--------+--------+
                rawByte = new byte[4];
                ms.Read(rawByte, 0, 4);
                rawByte = BytesTools.SwapBytes(rawByte);
                SetAsInteger(BitConverter.ToUInt32(rawByte, 0));
            }
            else if (lvByte == 0xCF)
            {
                //  uint 64 stores a 64-bit big-endian unsigned integer
                //  +--------+--------+--------+--------+--------+--------+--------+--------+--------+
                //  |  0xcf  |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|
                //  +--------+--------+--------+--------+--------+--------+--------+--------+--------+
                rawByte = new byte[8];
                ms.Read(rawByte, 0, 8);
                rawByte = BytesTools.SwapBytes(rawByte);
                SetAsUInt64(BitConverter.ToUInt64(rawByte, 0));
            }
            else if (lvByte == 0xDC)
            {
                //      +--------+--------+--------+~~~~~~~~~~~~~~~~~+
                //      |  0xdc  |YYYYYYYY|YYYYYYYY|    N objects    |
                //      +--------+--------+--------+~~~~~~~~~~~~~~~~~+
                rawByte = new byte[2];
                ms.Read(rawByte, 0, 2);
                rawByte = BytesTools.SwapBytes(rawByte);
                len = BitConverter.ToInt16(rawByte, 0);

                this.Clear();
                this.valueType = MsgPackType.Array;
                for (i = 0; i < len; i++)
                {
                    msgPack = InnerAdd();
                    msgPack.DecodeFromStream(ms);
                }
            }
            else if (lvByte == 0xDD)
            {
                //  +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
                //  |  0xdd  |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|    N objects    |
                //  +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
                rawByte = new byte[4];
                ms.Read(rawByte, 0, 4);
                rawByte = BytesTools.SwapBytes(rawByte);
                len = BitConverter.ToInt16(rawByte, 0);

                this.Clear();
                this.valueType = MsgPackType.Array;
                for (i = 0; i < len; i++)
                {
                    msgPack = InnerAdd();
                    msgPack.DecodeFromStream(ms);
                }
            }
            else if (lvByte == 0xD9)
            {
                //  str 8 stores a byte array whose length is upto (2^8)-1 bytes:
                //  +--------+--------+========+
                //  |  0xd9  |YYYYYYYY|  data  |
                //  +--------+--------+========+
                SetAsString(ReadTools.ReadString(lvByte, ms));
            }
            else if (lvByte == 0xDE)
            {
                //    +--------+--------+--------+~~~~~~~~~~~~~~~~~+
                //    |  0xde  |YYYYYYYY|YYYYYYYY|   N*2 objects   |
                //    +--------+--------+--------+~~~~~~~~~~~~~~~~~+
                rawByte = new byte[2];
                ms.Read(rawByte, 0, 2);
                rawByte = BytesTools.SwapBytes(rawByte);
                len = BitConverter.ToInt16(rawByte, 0);

                this.Clear();
                this.valueType = MsgPackType.Map;
                for (i = 0; i < len; i++)
                {
                    msgPack = InnerAdd();
                    msgPack.SetName(ReadTools.ReadString(ms));
                    msgPack.DecodeFromStream(ms);
                }
            }
            else if (lvByte == 0xDE)
            {
                //    +--------+--------+--------+~~~~~~~~~~~~~~~~~+
                //    |  0xde  |YYYYYYYY|YYYYYYYY|   N*2 objects   |
                //    +--------+--------+--------+~~~~~~~~~~~~~~~~~+
                rawByte = new byte[2];
                ms.Read(rawByte, 0, 2);
                rawByte = BytesTools.SwapBytes(rawByte);
                len = BitConverter.ToInt16(rawByte, 0);

                this.Clear();
                this.valueType = MsgPackType.Map;
                for (i = 0; i < len; i++)
                {
                    msgPack = InnerAdd();
                    msgPack.SetName(ReadTools.ReadString(ms));
                    msgPack.DecodeFromStream(ms);
                }
            }
            else if (lvByte == 0xDF)
            {
                //    +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
                //    |  0xdf  |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|   N*2 objects   |
                //    +--------+--------+--------+--------+--------+~~~~~~~~~~~~~~~~~+
                rawByte = new byte[4];
                ms.Read(rawByte, 0, 4);
                rawByte = BytesTools.SwapBytes(rawByte);
                len = BitConverter.ToInt32(rawByte, 0);

                this.Clear();
                this.valueType = MsgPackType.Map;
                for (i = 0; i < len; i++)
                {
                    msgPack = InnerAdd();
                    msgPack.SetName(ReadTools.ReadString(ms));
                    msgPack.DecodeFromStream(ms);
                }
            }
            else if (lvByte == 0xDA)
            {
                //      str 16 stores a byte array whose length is upto (2^16)-1 bytes:
                //      +--------+--------+--------+========+
                //      |  0xda  |ZZZZZZZZ|ZZZZZZZZ|  data  |
                //      +--------+--------+--------+========+
                SetAsString(ReadTools.ReadString(lvByte, ms));
            }
            else if (lvByte == 0xDB)
            {
                //  str 32 stores a byte array whose length is upto (2^32)-1 bytes:
                //  +--------+--------+--------+--------+--------+========+
                //  |  0xdb  |AAAAAAAA|AAAAAAAA|AAAAAAAA|AAAAAAAA|  data  |
                //  +--------+--------+--------+--------+--------+========+
                SetAsString(ReadTools.ReadString(lvByte, ms));
            }
            else if (lvByte == 0xD0)
            {
                //      int 8 stores a 8-bit signed integer
                //      +--------+--------+
                //      |  0xd0  |ZZZZZZZZ|
                //      +--------+--------+
                SetAsInteger((sbyte)ms.ReadByte());
            }
            else if (lvByte == 0xD1)
            {
                //    int 16 stores a 16-bit big-endian signed integer
                //    +--------+--------+--------+
                //    |  0xd1  |ZZZZZZZZ|ZZZZZZZZ|
                //    +--------+--------+--------+
                rawByte = new byte[2];
                ms.Read(rawByte, 0, 2);
                rawByte = BytesTools.SwapBytes(rawByte);
                SetAsInteger(BitConverter.ToInt16(rawByte, 0));
            }
            else if (lvByte == 0xD2)
            {
                //  int 32 stores a 32-bit big-endian signed integer
                //  +--------+--------+--------+--------+--------+
                //  |  0xd2  |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|
                //  +--------+--------+--------+--------+--------+
                rawByte = new byte[4];
                ms.Read(rawByte, 0, 4);
                rawByte = BytesTools.SwapBytes(rawByte);
                SetAsInteger(BitConverter.ToInt32(rawByte, 0));
            }
            else if (lvByte == 0xD3)
            {
                //  int 64 stores a 64-bit big-endian signed integer
                //  +--------+--------+--------+--------+--------+--------+--------+--------+--------+
                //  |  0xd3  |ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|ZZZZZZZZ|
                //  +--------+--------+--------+--------+--------+--------+--------+--------+--------+
                rawByte = new byte[8];
                ms.Read(rawByte, 0, 8);
                rawByte = BytesTools.SwapBytes(rawByte);
                SetAsInteger(BitConverter.ToInt64(rawByte, 0));
            }    
        }
        public static bool IsInteger(this MsgPackType formatType)
        {
            switch (formatType)
            {
            case MsgPackType.POSITIVE_FIXNUM:
            case MsgPackType.POSITIVE_FIXNUM_0x01:
            case MsgPackType.POSITIVE_FIXNUM_0x02:
            case MsgPackType.POSITIVE_FIXNUM_0x03:
            case MsgPackType.POSITIVE_FIXNUM_0x04:
            case MsgPackType.POSITIVE_FIXNUM_0x05:
            case MsgPackType.POSITIVE_FIXNUM_0x06:
            case MsgPackType.POSITIVE_FIXNUM_0x07:
            case MsgPackType.POSITIVE_FIXNUM_0x08:
            case MsgPackType.POSITIVE_FIXNUM_0x09:
            case MsgPackType.POSITIVE_FIXNUM_0x0A:
            case MsgPackType.POSITIVE_FIXNUM_0x0B:
            case MsgPackType.POSITIVE_FIXNUM_0x0C:
            case MsgPackType.POSITIVE_FIXNUM_0x0D:
            case MsgPackType.POSITIVE_FIXNUM_0x0E:
            case MsgPackType.POSITIVE_FIXNUM_0x0F:

            case MsgPackType.POSITIVE_FIXNUM_0x10:
            case MsgPackType.POSITIVE_FIXNUM_0x11:
            case MsgPackType.POSITIVE_FIXNUM_0x12:
            case MsgPackType.POSITIVE_FIXNUM_0x13:
            case MsgPackType.POSITIVE_FIXNUM_0x14:
            case MsgPackType.POSITIVE_FIXNUM_0x15:
            case MsgPackType.POSITIVE_FIXNUM_0x16:
            case MsgPackType.POSITIVE_FIXNUM_0x17:
            case MsgPackType.POSITIVE_FIXNUM_0x18:
            case MsgPackType.POSITIVE_FIXNUM_0x19:
            case MsgPackType.POSITIVE_FIXNUM_0x1A:
            case MsgPackType.POSITIVE_FIXNUM_0x1B:
            case MsgPackType.POSITIVE_FIXNUM_0x1C:
            case MsgPackType.POSITIVE_FIXNUM_0x1D:
            case MsgPackType.POSITIVE_FIXNUM_0x1E:
            case MsgPackType.POSITIVE_FIXNUM_0x1F:

            case MsgPackType.POSITIVE_FIXNUM_0x20:
            case MsgPackType.POSITIVE_FIXNUM_0x21:
            case MsgPackType.POSITIVE_FIXNUM_0x22:
            case MsgPackType.POSITIVE_FIXNUM_0x23:
            case MsgPackType.POSITIVE_FIXNUM_0x24:
            case MsgPackType.POSITIVE_FIXNUM_0x25:
            case MsgPackType.POSITIVE_FIXNUM_0x26:
            case MsgPackType.POSITIVE_FIXNUM_0x27:
            case MsgPackType.POSITIVE_FIXNUM_0x28:
            case MsgPackType.POSITIVE_FIXNUM_0x29:
            case MsgPackType.POSITIVE_FIXNUM_0x2A:
            case MsgPackType.POSITIVE_FIXNUM_0x2B:
            case MsgPackType.POSITIVE_FIXNUM_0x2C:
            case MsgPackType.POSITIVE_FIXNUM_0x2D:
            case MsgPackType.POSITIVE_FIXNUM_0x2E:
            case MsgPackType.POSITIVE_FIXNUM_0x2F:

            case MsgPackType.POSITIVE_FIXNUM_0x30:
            case MsgPackType.POSITIVE_FIXNUM_0x31:
            case MsgPackType.POSITIVE_FIXNUM_0x32:
            case MsgPackType.POSITIVE_FIXNUM_0x33:
            case MsgPackType.POSITIVE_FIXNUM_0x34:
            case MsgPackType.POSITIVE_FIXNUM_0x35:
            case MsgPackType.POSITIVE_FIXNUM_0x36:
            case MsgPackType.POSITIVE_FIXNUM_0x37:
            case MsgPackType.POSITIVE_FIXNUM_0x38:
            case MsgPackType.POSITIVE_FIXNUM_0x39:
            case MsgPackType.POSITIVE_FIXNUM_0x3A:
            case MsgPackType.POSITIVE_FIXNUM_0x3B:
            case MsgPackType.POSITIVE_FIXNUM_0x3C:
            case MsgPackType.POSITIVE_FIXNUM_0x3D:
            case MsgPackType.POSITIVE_FIXNUM_0x3E:
            case MsgPackType.POSITIVE_FIXNUM_0x3F:

            case MsgPackType.POSITIVE_FIXNUM_0x40:
            case MsgPackType.POSITIVE_FIXNUM_0x41:
            case MsgPackType.POSITIVE_FIXNUM_0x42:
            case MsgPackType.POSITIVE_FIXNUM_0x43:
            case MsgPackType.POSITIVE_FIXNUM_0x44:
            case MsgPackType.POSITIVE_FIXNUM_0x45:
            case MsgPackType.POSITIVE_FIXNUM_0x46:
            case MsgPackType.POSITIVE_FIXNUM_0x47:
            case MsgPackType.POSITIVE_FIXNUM_0x48:
            case MsgPackType.POSITIVE_FIXNUM_0x49:
            case MsgPackType.POSITIVE_FIXNUM_0x4A:
            case MsgPackType.POSITIVE_FIXNUM_0x4B:
            case MsgPackType.POSITIVE_FIXNUM_0x4C:
            case MsgPackType.POSITIVE_FIXNUM_0x4D:
            case MsgPackType.POSITIVE_FIXNUM_0x4E:
            case MsgPackType.POSITIVE_FIXNUM_0x4F:

            case MsgPackType.POSITIVE_FIXNUM_0x50:
            case MsgPackType.POSITIVE_FIXNUM_0x51:
            case MsgPackType.POSITIVE_FIXNUM_0x52:
            case MsgPackType.POSITIVE_FIXNUM_0x53:
            case MsgPackType.POSITIVE_FIXNUM_0x54:
            case MsgPackType.POSITIVE_FIXNUM_0x55:
            case MsgPackType.POSITIVE_FIXNUM_0x56:
            case MsgPackType.POSITIVE_FIXNUM_0x57:
            case MsgPackType.POSITIVE_FIXNUM_0x58:
            case MsgPackType.POSITIVE_FIXNUM_0x59:
            case MsgPackType.POSITIVE_FIXNUM_0x5A:
            case MsgPackType.POSITIVE_FIXNUM_0x5B:
            case MsgPackType.POSITIVE_FIXNUM_0x5C:
            case MsgPackType.POSITIVE_FIXNUM_0x5D:
            case MsgPackType.POSITIVE_FIXNUM_0x5E:
            case MsgPackType.POSITIVE_FIXNUM_0x5F:

            case MsgPackType.POSITIVE_FIXNUM_0x60:
            case MsgPackType.POSITIVE_FIXNUM_0x61:
            case MsgPackType.POSITIVE_FIXNUM_0x62:
            case MsgPackType.POSITIVE_FIXNUM_0x63:
            case MsgPackType.POSITIVE_FIXNUM_0x64:
            case MsgPackType.POSITIVE_FIXNUM_0x65:
            case MsgPackType.POSITIVE_FIXNUM_0x66:
            case MsgPackType.POSITIVE_FIXNUM_0x67:
            case MsgPackType.POSITIVE_FIXNUM_0x68:
            case MsgPackType.POSITIVE_FIXNUM_0x69:
            case MsgPackType.POSITIVE_FIXNUM_0x6A:
            case MsgPackType.POSITIVE_FIXNUM_0x6B:
            case MsgPackType.POSITIVE_FIXNUM_0x6C:
            case MsgPackType.POSITIVE_FIXNUM_0x6D:
            case MsgPackType.POSITIVE_FIXNUM_0x6E:
            case MsgPackType.POSITIVE_FIXNUM_0x6F:

            case MsgPackType.POSITIVE_FIXNUM_0x70:
            case MsgPackType.POSITIVE_FIXNUM_0x71:
            case MsgPackType.POSITIVE_FIXNUM_0x72:
            case MsgPackType.POSITIVE_FIXNUM_0x73:
            case MsgPackType.POSITIVE_FIXNUM_0x74:
            case MsgPackType.POSITIVE_FIXNUM_0x75:
            case MsgPackType.POSITIVE_FIXNUM_0x76:
            case MsgPackType.POSITIVE_FIXNUM_0x77:
            case MsgPackType.POSITIVE_FIXNUM_0x78:
            case MsgPackType.POSITIVE_FIXNUM_0x79:
            case MsgPackType.POSITIVE_FIXNUM_0x7A:
            case MsgPackType.POSITIVE_FIXNUM_0x7B:
            case MsgPackType.POSITIVE_FIXNUM_0x7C:
            case MsgPackType.POSITIVE_FIXNUM_0x7D:
            case MsgPackType.POSITIVE_FIXNUM_0x7E:
            case MsgPackType.POSITIVE_FIXNUM_0x7F:

            case MsgPackType.NEGATIVE_FIXNUM:
            case MsgPackType.NEGATIVE_FIXNUM_0x01:
            case MsgPackType.NEGATIVE_FIXNUM_0x02:
            case MsgPackType.NEGATIVE_FIXNUM_0x03:
            case MsgPackType.NEGATIVE_FIXNUM_0x04:
            case MsgPackType.NEGATIVE_FIXNUM_0x05:
            case MsgPackType.NEGATIVE_FIXNUM_0x06:
            case MsgPackType.NEGATIVE_FIXNUM_0x07:
            case MsgPackType.NEGATIVE_FIXNUM_0x08:
            case MsgPackType.NEGATIVE_FIXNUM_0x09:
            case MsgPackType.NEGATIVE_FIXNUM_0x0A:
            case MsgPackType.NEGATIVE_FIXNUM_0x0B:
            case MsgPackType.NEGATIVE_FIXNUM_0x0C:
            case MsgPackType.NEGATIVE_FIXNUM_0x0D:
            case MsgPackType.NEGATIVE_FIXNUM_0x0E:
            case MsgPackType.NEGATIVE_FIXNUM_0x0F:
            case MsgPackType.NEGATIVE_FIXNUM_0x10:
            case MsgPackType.NEGATIVE_FIXNUM_0x11:
            case MsgPackType.NEGATIVE_FIXNUM_0x12:
            case MsgPackType.NEGATIVE_FIXNUM_0x13:
            case MsgPackType.NEGATIVE_FIXNUM_0x14:
            case MsgPackType.NEGATIVE_FIXNUM_0x15:
            case MsgPackType.NEGATIVE_FIXNUM_0x16:
            case MsgPackType.NEGATIVE_FIXNUM_0x17:
            case MsgPackType.NEGATIVE_FIXNUM_0x18:
            case MsgPackType.NEGATIVE_FIXNUM_0x19:
            case MsgPackType.NEGATIVE_FIXNUM_0x1A:
            case MsgPackType.NEGATIVE_FIXNUM_0x1B:
            case MsgPackType.NEGATIVE_FIXNUM_0x1C:
            case MsgPackType.NEGATIVE_FIXNUM_0x1D:
            case MsgPackType.NEGATIVE_FIXNUM_0x1E:
            case MsgPackType.NEGATIVE_FIXNUM_0x1F:

            case MsgPackType.INT8:
            case MsgPackType.INT16:
            case MsgPackType.INT32:
            case MsgPackType.INT64:
            case MsgPackType.UINT8:
            case MsgPackType.UINT16:
            case MsgPackType.UINT32:
            case MsgPackType.UINT64:
                return(true);

            default:
                return(false);
            }
        }