Пример #1
0
        private void WriteMap(Stream ms)
        {
            byte b;

            byte[] lenBytes;
            int    len = children.Count;

            if (len <= 15)
            {
                b = (byte)(0x80 + (byte)len);
                ms.WriteByte(b);
            }
            else if (len <= 65535)
            {
                b = 0xDE;
                ms.WriteByte(b);

                lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int16)len));
                ms.Write(lenBytes, 0, lenBytes.Length);
            }
            else
            {
                b = 0xDF;
                ms.WriteByte(b);
                lenBytes = BytesTools.SwapBytes(BitConverter.GetBytes((Int32)len));
                ms.Write(lenBytes, 0, lenBytes.Length);
            }

            for (int i = 0; i < len; i++)
            {
                WriteTools.WriteString(ms, children[i].name);
                children[i].Encode2Stream(ms);
            }
        }
Пример #2
0
        public void Encode2Stream(Stream ms)
        {
            switch (this.valueType)
            {
            case MsgPackType.Unknown:
            case MsgPackType.Null:
                WriteTools.WriteNull(ms);
                break;

            case MsgPackType.String:
                WriteTools.WriteString(ms, (String)this.innerValue);
                break;

            case MsgPackType.Integer:
                WriteTools.WriteInteger(ms, (Int64)this.innerValue);
                break;

            case MsgPackType.UInt64:
                WriteTools.WriteUInt64(ms, (UInt64)this.innerValue);
                break;

            case MsgPackType.Boolean:
                WriteTools.WriteBoolean(ms, (Boolean)this.innerValue);
                break;

            case MsgPackType.Float:
                WriteTools.WriteFloat(ms, (Double)this.innerValue);
                break;

            case MsgPackType.Single:
                WriteTools.WriteFloat(ms, (Single)this.innerValue);
                break;

            case MsgPackType.DateTime:
                WriteTools.WriteInteger(ms, GetAsInteger());
                break;

            case MsgPackType.Binary:
                WriteTools.WriteBinary(ms, (byte[])this.innerValue);
                break;

            case MsgPackType.Map:
                WriteMap(ms);
                break;

            case MsgPackType.Array:
                WirteArray(ms);
                break;

            default:
                WriteTools.WriteNull(ms);
                break;
            }
        }