public JsonBufferWriter(int initialCapacity) { if (initialCapacity < 0) { throw new ArgumentOutOfRangeException("initialCapacity", initialCapacity, null); } _storage = new JsonBufferStorage(initialCapacity); }
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; }
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); }
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()); }