Exemplo n.º 1
0
        /// <summary>
        /// 对象转换XML字符串
        /// </summary>
        /// <typeparam name="valueType">目标数据类型</typeparam>
        /// <param name="value">数据对象</param>
        private void serialize <valueType>(valueType value)
        {
            Warning = SerializeWarning.None;
            if (checkLoopDepth != Config.CheckLoopDepth)
            {
                if (Config.CheckLoopDepth <= 0)
                {
                    checkLoopDepth = 0;
                    if (forefather == null)
                    {
                        forefather = new object[sizeof(int)];
                    }
                }
                else
                {
                    checkLoopDepth = Config.CheckLoopDepth;
                }
            }
            CharStream.Write(Config.Header);
            fixed(char *nameFixed = Config.BootNodeName)
            {
                nameStart(nameFixed, Config.BootNodeName.Length);
                TypeSerializer <valueType> .Serialize(this, value);

                nameEnd(nameFixed, Config.BootNodeName.Length);
            }
        }
        public void CallSerialize(Node value)
        {
            switch (value.Type)
            {
            case NodeType.String:
                CallSerialize(value.String);
                return;

            case NodeType.EncodeString:
                CharStream.Write(value.String);
                return;

            case NodeType.TempString:
                CharStream.Write(value.String);
                return;

            case NodeType.ErrorString:
                return;

            case NodeType.Node:
                foreach (KeyValue <SubString, Node> node in value.Nodes)
                {
                    fixed(char *nameFixed = node.Key.GetFixedBuffer())
                    {
                        nameStart(nameFixed + node.Key.Start, node.Key.Length);
                        CallSerialize(node.Value);
                        nameEnd(nameFixed + node.Key.Start, node.Key.Length);
                    }
                }
                return;
            }
        }
Exemplo n.º 3
0
        public void CallSerialize(ulong[] array)
        {
            if (array != null)
            {
                switch (array.Length)
                {
                case 0: CharStream.WriteJsonArray(); return;

                case 1:
                    CharStream.Write('[');
                    CallSerialize(array[0]);
                    CharStream.Write(']');
                    return;

                default:
                    bool isNext = false;
                    CharStream.Write('[');
                    foreach (ulong value in array)
                    {
                        if (isNext)
                        {
                            CharStream.Write(',');
                        }
                        else
                        {
                            isNext = true;
                        }
                        CallSerialize(value);
                    }
                    CharStream.Write(']');
                    return;
                }
            }
            CharStream.WriteJsonNull();
        }
Exemplo n.º 4
0
        internal void Pop()
        {
            if (checkLoopDepth == 0)
            {
                forefather[--forefatherCount] = null;
            }
            else
            {
                ++checkLoopDepth;
#if AutoCSer
                if (isLoopObject)
                {
                    CharStream.Write(')');
                }
#endif
            }
        }
 public void CallSerialize(bool value)
 {
     if (!Config.IsBoolToInt)
     {
         CharStream.WriteJsonBool(value);
     }
     else
     {
         CharStream.Write(value ? '1' : '0');
     }
 }
        public void CallSerialize(char value)
        {
            if (((bits[(byte)value] & XmlDeSerializer.EncodeSpaceBit) | (value & 0xff00)) == 0)
            {
                switch ((byte)value)
                {
                case (byte)'\t':
                    *(long *)CharStream.GetBeforeMove(4 * sizeof(char)) = '&' + ('#' << 16) + ((long)'9' << 32) + ((long)';' << 48);
                    return;

                case (byte)'\n':
                    byte *data10 = CharStream.GetBeforeMove(5 * sizeof(char));
                    *(long *)data10 = '&' + ('#' << 16) + ((long)'1' << 32) + ((long)'0' << 48);
                    *(char *)(data10 + sizeof(long)) = ';';
                    return;

                case (byte)'\r':
                    byte *data13 = CharStream.GetBeforeMove(5 * sizeof(char));
                    *(long *)data13 = '&' + ('#' << 16) + ((long)'1' << 32) + ((long)'3' << 48);
                    *(char *)(data13 + sizeof(long)) = ';';
                    return;

                case (byte)' ':
                    byte *data32 = CharStream.GetBeforeMove(5 * sizeof(char));
                    *(long *)data32 = '&' + ('#' << 16) + ((long)'3' << 32) + ((long)'2' << 48);
                    *(char *)(data32 + sizeof(long)) = ';';
                    return;

                case (byte)'&':
                    byte *data38 = CharStream.GetBeforeMove(5 * sizeof(char));
                    *(long *)data38 = '&' + ('#' << 16) + ((long)'3' << 32) + ((long)'8' << 48);
                    *(char *)(data38 + sizeof(long)) = ';';
                    return;

                case (byte)'<':
                    *(long *)CharStream.GetBeforeMove(4 * sizeof(char)) = '&' + ('l' << 16) + ((long)'t' << 32) + ((long)';' << 48);
                    return;

                case (byte)'>':
                    *(long *)CharStream.GetBeforeMove(4 * sizeof(char)) = '&' + ('g' << 16) + ((long)'t' << 32) + ((long)';' << 48);
                    return;
                }
            }
            CharStream.Write(value);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        private void serialize(ref Node value)
        {
            switch (value.Type)
            {
            case NodeType.Dictionary:
                CharStream.Write('{');
                if ((int)value.Int64 != 0)
                {
                    KeyValue <Node, Node>[] array = value.DictionaryArray;
                    for (int index = 0; index != (int)value.Int64; ++index)
                    {
                        if (index != 0)
                        {
                            CharStream.Write(',');
                        }
                        serialize(ref array[index].Key);
                        CharStream.Write(':');
                        serialize(ref array[index].Value);
                    }
                }
                CharStream.Write('}');
                return;

            case NodeType.Array:
                CharStream.Write('[');
                if ((int)value.Int64 != 0)
                {
                    Node[] array = value.ListArray;
                    for (int index = 0; index != (int)value.Int64; ++index)
                    {
                        if (index != 0)
                        {
                            CharStream.Write(',');
                        }
                        serialize(ref array[index]);
                        CharStream.Write(':');
                        serialize(ref array[index]);
                    }
                }
                CharStream.Write(']');
                return;

            case NodeType.String:
            {
                SubString subString = value.SubString;
                CharStream.WriteJson(ref subString, Config.NullChar);
            }
                return;

            case NodeType.QuoteString:
            case NodeType.ErrorQuoteString:
                CharStream.PrepCharSize(value.SubString.Length + 2);
                CharStream.Data.Write((char)value.Int64);
                CharStream.Write(ref value.SubString);
                CharStream.Data.Write((char)value.Int64);
                return;

            case NodeType.NumberString:
                if ((int)value.Int64 == 0)
                {
                    CharStream.Write(ref value.SubString);
                }
                else
                {
                    CharStream.PrepCharSize(value.SubString.Length + 2);
                    CharStream.Data.Write((char)value.Int64);
                    CharStream.Write(ref value.SubString);
                    CharStream.Data.Write((char)value.Int64);
                }
                return;

            case NodeType.Bool:
                CallSerialize((int)value.Int64 != 0);
                return;

            case NodeType.DateTimeTick:
                CallSerialize(new DateTime(value.Int64, DateTimeKind.Local));
                return;

            case NodeType.NaN:
                CharStream.WriteJsonNaN();
                return;

            case NodeType.PositiveInfinity:
                if (Config.IsInfinityToNaN)
                {
                    CharStream.WriteJsonNaN();
                }
                else
                {
                    CharStream.WritePositiveInfinity();
                }
                return;

            case NodeType.NegativeInfinity:
                if (Config.IsInfinityToNaN)
                {
                    CharStream.WriteJsonNaN();
                }
                else
                {
                    CharStream.WriteNegativeInfinity();
                }
                return;

            default:
                CharStream.WriteJsonNull();
                return;
            }
        }