예제 #1
0
        internal static void Write(this JsonOperationContext.SyncJsonOperationContext syncContext, Stream stream, BlittableJsonReaderObject json)
        {
            syncContext.EnsureNotDisposed();

            using (var writer = new BlittableJsonTextWriter(syncContext.Context, stream))
            {
                writer.WriteObject(json);
            }
        }
예제 #2
0
        public static BlittableJsonReaderObject ParseToMemory(
            this JsonOperationContext.SyncJsonOperationContext syncContext,
            Stream stream,
            string debugTag,
            BlittableJsonDocumentBuilder.UsageMode mode,
            JsonOperationContext.MemoryBuffer bytes,
            IBlittableDocumentModifier modifier = null)
        {
            syncContext.EnsureNotDisposed();

            syncContext.JsonParserState.Reset();
            using (var parser = new UnmanagedJsonParser(syncContext.Context, syncContext.JsonParserState, debugTag))
                using (var builder = new BlittableJsonDocumentBuilder(syncContext.Context, mode, debugTag, parser, syncContext.JsonParserState, modifier: modifier))
                {
                    syncContext.Context.CachedProperties.NewDocument();
                    builder.ReadObjectDocument();
                    while (true)
                    {
                        if (bytes.Valid == bytes.Used)
                        {
                            var read = stream.Read(bytes.Memory.Memory.Span);
                            syncContext.EnsureNotDisposed();
                            if (read == 0)
                            {
                                throw new EndOfStreamException("Stream ended without reaching end of json content");
                            }
                            bytes.Valid = read;
                            bytes.Used  = 0;
                        }
                        parser.SetBuffer(bytes);
                        var result = builder.Read();
                        bytes.Used += parser.BufferOffset;
                        if (result)
                        {
                            break;
                        }
                    }
                    builder.FinalizeDocument();

                    var reader = builder.CreateReader();
                    return(reader);
                }
        }