public void EncodeRecord(DxRecordValue value)
            {
                int maplen = value.Count;

                if (maplen <= Max_fixmap_len) //fixmap
                {
                    databuffer.WriteByte((byte)(0x80 | (byte)maplen));
                }
                else if (maplen <= Max_map16_len)
                {
                    WriteUint16((ushort)maplen, MsgPackCode.CodeMap16);
                }
                else
                {
                    if (maplen > Max_map32_len)
                    {
                        maplen = Max_map32_len;
                    }
                    WriteUint32((uint)maplen, MsgPackCode.CodeMap32);
                }
                //写入KV
                foreach (KeyValuePair <string, DxBaseValue> kvalue in value)
                {
                    EncodeString(kvalue.Key);
                    if (kvalue.Value == null)
                    {
                        databuffer.WriteByte((byte)MsgPackCode.CodeNil);
                    }
                    else
                    {
                        Encode(kvalue.Value);
                    }
                }
            }
            public bool DecodeMap(MsgPackCode code, out DxRecordValue value)
            {
                value = null;
                if (code == MsgPackCode.CodeUnkonw)
                {
                    bool result = ReadCode(out code);
                    if (!result)
                    {
                        return(false);
                    }
                }
                uint maplen;

                if (!DecodeMapLen(code, out maplen))
                {
                    return(false);
                }
                if (maplen == 0)
                {
                    return(true);
                }
                if (!ReadCode(out code) || !IsStr(code))
                {
                    return(false);
                }
                value = new DxRecordValue();
                if (!DecodeMapKv(value, code))
                {
                    return(false);
                }
                for (int i = 1; i < maplen; i++)
                {
                    if (!DecodeMapKv(value, MsgPackCode.CodeUnkonw))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            public DxBaseValue Parser()
            {
                MsgPackCode code;

                if (!ReadCode(out code))
                {
                    return(null);
                }
                //判断类型
                if (IsStr(code))
                {
                    string value;
                    if (DecodeString(code, out value))
                    {
                        return(new DxStringValue(value));
                    }
                    return(null);
                }
                else if (IsFixedNum(code))
                {
                    return(new DxIntValue((int)code));
                }
                else if (IsInt(code))
                {
                    long v = 0;
                    if (DecodeInt(code, out v))
                    {
                        if (v <= int.MaxValue && v >= int.MinValue)
                        {
                            return(new DxIntValue((int)v));
                        }
                        else
                        {
                            return(new DxInt64Value(v));
                        }
                    }
                }
                else if (IsMap(code))
                {
                    DxRecordValue result = null;
                    if (DecodeMap(code, out result))
                    {
                        return(result);
                    }
                }
                else if (IsArray(code))
                {
                    DxArrayValue result = new DxArrayValue();
                    if (!Decode2Array(code, result))
                    {
                        return(null);
                    }
                    return(result);
                }
                else if (IsBin(code))
                {
                    byte[] binary;
                    if (!DecodeBinary(code, out binary))
                    {
                        return(null);
                    }
                    if (binary != null)
                    {
                        DxBinaryValue binaryValue = new DxBinaryValue();
                        binaryValue.Bytes = binary;
                        return(binaryValue);
                    }
                }
                else if (IsExt(code))
                {
                    byte[] binary;
                    if (!DecodeExtValue(code, out binary))
                    {
                        return(null);
                    }
                    if (binary.Length == 13 && (sbyte)binary[0] == -1) //96位日期格式
                    {
                        //32位纳秒,64位秒
                        Stream stream = new MemoryStream(binary);
                        stream.Position = 1;
                        uint  nsec = BigEndian.Uint32(stream);
                        ulong sec  = BigEndian.Uint64(stream);
                        stream.Dispose();
                        System.DateTime dateTime = new System.DateTime(1970, 1, 1);
                        double          sec1     = nsec / (1000 * 1000);
                        return(new DxDateTimeValue(dateTime.AddSeconds(sec + sec1)));
                    }
                    else
                    {
                        return(new DxExtValue(binary));
                    }
                }
                else
                {
                    switch (code)
                    {
                    case MsgPackCode.CodeTrue:
                        return(new DxBoolValue(true));

                    case MsgPackCode.CodeFalse:
                        return(new DxBoolValue(false));

                    case MsgPackCode.CodeFloat:
                        uint v = BigEndian.Uint32(buffer);
                        return(new DxFloatValue((float)System.BitConverter.Int64BitsToDouble((long)v)));

                    case MsgPackCode.CodeDouble:
                        ulong v1 = BigEndian.Uint64(buffer);
                        return(new DxDoubleValue(System.BitConverter.Int64BitsToDouble((long)v1)));

                    case MsgPackCode.CodeFixExt4:
                        if (!ReadCode(out code))
                        {
                            return(null);
                        }
                        if ((sbyte)code == -1)     //时间
                        {
                            uint            seconds  = BigEndian.Uint32(buffer);
                            System.DateTime dateTime = new System.DateTime(1970, 1, 1);
                            return(new DxDateTimeValue(dateTime.AddSeconds((double)seconds)));
                        }
                        else
                        {
                            byte[] bt = new byte[5];
                            buffer.Read(bt, 1, 4);
                            return(new DxExtValue(bt));
                        }

                    case MsgPackCode.CodeFixExt8:
                        //64位时间格式
                        if (!ReadCode(out code))
                        {
                            return(null);
                        }
                        if ((sbyte)code == -1)     //时间
                        {
                            ulong seconds = BigEndian.Uint64(buffer);
                            long  nsec    = (long)(seconds >> 34);
                            seconds &= 0x00000003ffffffff;
                            System.DateTime dateTime = new System.DateTime(1970, 1, 1);
                            double          sec1     = nsec / (1000 * 1000);
                            return(new DxDateTimeValue(dateTime.AddSeconds(seconds + sec1)));
                        }
                        else
                        {
                            byte[] bt = new byte[9];
                            buffer.Read(bt, 1, 8);
                            return(new DxExtValue(bt));
                        }
                    }
                }

                return(null);
            }
            public bool DecodeMapKv(DxRecordValue mapValue, MsgPackCode code)
            {
                string key;

                if (!DecodeString(code, out key))
                {
                    return(false);
                }
                if (!ReadCode(out code))
                {
                    return(false);
                }
                if (IsStr(code))
                {
                    string value;
                    if (!DecodeString(code, out value))
                    {
                        return(false);
                    }
                    mapValue.SetString(key, value);
                }
                else if (IsFixedNum(code))
                {
                    mapValue.SetInt(key, (int)(sbyte)code);
                }
                else if (IsInt(code))
                {
                    long v;
                    if (!DecodeInt(code, out v))
                    {
                        return(false);
                    }
                    if (v > int.MaxValue || v < int.MinValue)
                    {
                        mapValue.SetInt64(key, v);
                    }
                    else
                    {
                        mapValue.SetInt(key, (int)v);
                    }
                }
                else if (IsMap(code))
                {
                    DxRecordValue v;
                    if (!DecodeMap(code, out v))
                    {
                        return(false);
                    }
                    mapValue[key] = v;
                }
                else if (IsArray(code))
                {
                    DxArrayValue arr = new DxArrayValue();
                    if (!Decode2Array(code, arr))
                    {
                        return(false);
                    }
                    mapValue[key] = arr;
                }
                else if (IsBin(code))
                {
                    byte[] binary;
                    if (!DecodeBinary(code, out binary))
                    {
                        return(false);
                    }
                    if (binary != null)
                    {
                        DxBinaryValue binaryValue = new DxBinaryValue();
                        binaryValue.Bytes = binary;
                        mapValue[key]     = binaryValue;
                    }
                }
                else if (IsExt(code))
                {
                    byte[] binary;
                    if (!DecodeExtValue(code, out binary))
                    {
                        return(false);
                    }
                    if (binary.Length == 13 && (sbyte)binary[0] == -1) //96位日期格式
                    {
                        //32位纳秒,64位秒
                        Stream stream = new MemoryStream(binary);
                        stream.Position = 1;
                        uint  nsec = BigEndian.Uint32(stream);
                        ulong sec  = BigEndian.Uint64(stream);
                        stream.Dispose();
                        System.DateTime dateTime = new System.DateTime(1970, 1, 1);
                        double          sec1     = nsec / (1000 * 1000);
                        mapValue.SetDateTime(key, dateTime.AddSeconds(sec + sec1));
                    }
                    else
                    {
                        mapValue[key] = new DxExtValue(binary);
                    }
                }
                else
                {
                    switch (code)
                    {
                    case MsgPackCode.CodeTrue:
                        mapValue.SetBool(key, true);
                        return(true);

                    case MsgPackCode.CodeFalse:
                        mapValue.SetBool(key, false);
                        return(true);

                    case MsgPackCode.CodeNil:
                        mapValue[key] = null;
                        return(true);

                    case MsgPackCode.CodeFloat:
                        uint v = BigEndian.Uint32(buffer);
                        mapValue.SetFloat(key, (float)System.BitConverter.Int64BitsToDouble((long)v));
                        return(true);

                    case MsgPackCode.CodeDouble:
                        ulong v1 = BigEndian.Uint64(buffer);
                        mapValue.SetDouble(key, System.BitConverter.Int64BitsToDouble((long)v1));
                        return(true);

                    case MsgPackCode.CodeFixExt4:
                        if (!ReadCode(out code))
                        {
                            return(false);
                        }
                        if ((sbyte)code == -1)    //时间
                        {
                            uint            seconds  = BigEndian.Uint32(buffer);
                            System.DateTime dateTime = new System.DateTime(1970, 1, 1);
                            mapValue.SetDateTime(key, dateTime.AddSeconds((double)seconds));
                        }
                        else
                        {
                            byte[] bt = new byte[5];
                            buffer.Read(bt, 1, 4);
                            DxExtValue dxExtValue = new DxExtValue(bt);
                            mapValue[key] = dxExtValue;
                        }
                        return(true);

                    case MsgPackCode.CodeFixExt8:
                        //64位时间格式
                        if (!ReadCode(out code))
                        {
                            return(false);
                        }
                        if ((sbyte)code == -1)     //时间
                        {
                            ulong seconds = BigEndian.Uint64(buffer);
                            long  nsec    = (long)(seconds >> 34);
                            seconds &= 0x00000003ffffffff;
                            System.DateTime dateTime = new System.DateTime(1970, 1, 1);
                            double          sec1     = nsec / (1000 * 1000);
                            mapValue.SetDateTime(key, dateTime.AddSeconds(seconds + sec1));
                        }
                        else
                        {
                            byte[] bt = new byte[9];
                            buffer.Read(bt, 1, 8);
                            DxExtValue dxExtValue = new DxExtValue(bt);
                            mapValue[key] = dxExtValue;
                        }
                        return(true);
                    }
                }
                return(true);
            }