コード例 #1
0
        public bool TryReadObject(out JsonObjectReader reader, ref JsonObjectFileInfo fileInfo)
        {
            fileInfo.StartLine = fileInfo.EndLine;

            int status;
            var length = ReadObject(out status, ref fileInfo);

            if (status == KResultInvalidJson)
            {
                throw new Exception($"JsonStreamReader.TryReadObject expected '{{' as the next character. Line=[{fileInfo.EndLine}]");
            }

            if (status != KResultSuccess)
            {
                reader = new JsonObjectReader
                {
                    Line = fileInfo.StartLine
                };

                return(false);
            }

            reader = new JsonObjectReader(m_ObjectBuffer, 0, length)
            {
                Line = fileInfo.StartLine
            };
            return(true);
        }
コード例 #2
0
            public static void TranslateObject(ref JsonObjectReader reader, BinaryWriter writer)
            {
                writer.Write(BinaryToken.BeginObject);
                writer.Write((uint)0);
                s_PositionStack.Push(writer.BaseStream.Position);

                reader.ReadBeginObject();
                while (reader.ReadInObject())
                {
                    var propertyName = reader.ReadPropertyName();

                    writer.Write(BinaryToken.Property);
                    writer.Write(propertyName);

                    TranslateValue(ref reader, writer);
                }

                writer.Write(BinaryToken.EndObject);
                PrependSize(writer);
            }
コード例 #3
0
            private static void TranslateValue(ref JsonObjectReader reader, BinaryWriter writer)
            {
                var token = reader.GetCurrentJsonToken();

                switch (token)
                {
                case JsonObjectReader.JsonToken.BeginArray:
                {
                    writer.Write(BinaryToken.BeginArray);
                    writer.Write((uint)0);
                    s_PositionStack.Push(writer.BaseStream.Position);
                    reader.ReadBeginArray();
                    while (reader.ReadInArray())
                    {
                        TranslateValue(ref reader, writer);
                    }
                    writer.Write(BinaryToken.EndArray);
                    PrependSize(writer);
                }
                break;

                case JsonObjectReader.JsonToken.BeginObject:
                {
                    TranslateObject(ref reader, writer);
                }
                break;

                case JsonObjectReader.JsonToken.Number:
                {
                    writer.Write(BinaryToken.Value);
                    writer.Write((byte)TypeCode.Double);
                    writer.Write(double.Parse(reader.ReadNumber(), NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture));
                }
                break;

                case JsonObjectReader.JsonToken.String:
                {
                    writer.Write(BinaryToken.Value);
                    writer.Write((byte)TypeCode.String);
                    writer.Write(reader.ReadString());
                }
                break;

                case JsonObjectReader.JsonToken.True:
                case JsonObjectReader.JsonToken.False:
                {
                    writer.Write(BinaryToken.Value);
                    writer.Write((byte)TypeCode.Boolean);
                    writer.Write(reader.ReadBoolean());
                }
                break;

                case JsonObjectReader.JsonToken.Null:
                case JsonObjectReader.JsonToken.None:
                case JsonObjectReader.JsonToken.EndObject:
                case JsonObjectReader.JsonToken.EndArray:
                case JsonObjectReader.JsonToken.ValueSeparator:
                case JsonObjectReader.JsonToken.NameSeparator:
                {
                    reader.ReadUntilValueSeparator();
                }
                break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }