Exemple #1
0
        public JsonBufferWriter(int initialCapacity)
        {
            if (initialCapacity < 0)
                throw new ArgumentOutOfRangeException("initialCapacity", initialCapacity, null);

            _storage = new JsonBufferStorage(initialCapacity);
        }
        public JsonBufferWriter(int initialCapacity)
        {
            if (initialCapacity < 0)
            {
                throw new ArgumentOutOfRangeException("initialCapacity", initialCapacity, null);
            }

            _storage = new JsonBufferStorage(initialCapacity);
        }
Exemple #3
0
        internal JsonBuffer(JsonBufferStorage storage, int start, int end)
        {
            Debug.Assert(storage != null);
            Debug.Assert(start >= 0);
            Debug.Assert(end >= start);

            _storage = storage;
            _start = start;
            _end = end;
        }
Exemple #4
0
        internal JsonBuffer(JsonBufferStorage storage, int start, int end)
        {
            Debug.Assert(storage != null);
            Debug.Assert(start >= 0);
            Debug.Assert(end >= start);

            _storage = storage;
            _start   = start;
            _end     = end;
        }
Exemple #5
0
        static JsonBuffer()
        {
            JsonBuffer buffer = new JsonBufferStorage(5) // [null,true,false]
                .Write(JsonToken.Array())
                    .Write(JsonToken.Null(), JsonToken.True(), JsonToken.False())
                .Write(JsonToken.EndArray())
                .ToBuffer();

            _null = buffer.Slice(1, 2);
            _true = buffer.Slice(2, 3);
            _false = buffer.Slice(3, 4);
        }
Exemple #6
0
        static JsonBuffer()
        {
            JsonBuffer buffer = new JsonBufferStorage(5) // [null,true,false]
                                .Write(JsonToken.Array())
                                .Write(JsonToken.Null(), JsonToken.True(), JsonToken.False())
                                .Write(JsonToken.EndArray())
                                .ToBuffer();

            _null  = buffer.Slice(1, 2);
            _true  = buffer.Slice(2, 3);
            _false = buffer.Slice(3, 4);
        }
Exemple #7
0
        public static JsonBuffer From(JsonToken token)
        {
            JsonTokenClass clazz = token.Class;

            if (clazz == JsonTokenClass.Null)
            {
                return(_null);
            }

            if (!clazz.IsScalar)
            {
                throw new ArgumentException("Token must represent a JSON scalar value or null.", "token");
            }

            if (clazz == JsonTokenClass.Boolean)
            {
                return(token.Equals(JsonToken.True()) ? _true : _false);
            }

            JsonBufferStorage storage = new JsonBufferStorage(1);

            storage.Write(token);
            return(storage.ToBuffer());
        }
Exemple #8
0
        public static JsonBuffer From(JsonToken token)
        {
            JsonTokenClass clazz = token.Class;

            if (clazz == JsonTokenClass.Null)
                return _null;

            if (!clazz.IsScalar)
                throw new ArgumentException("Token must represent a JSON scalar value or null.", "token");

            if (clazz == JsonTokenClass.Boolean)
                return token.Equals(JsonToken.True()) ? _true : _false;

            JsonBufferStorage storage = new JsonBufferStorage(1);
            storage.Write(token);
            return storage.ToBuffer();
        }