Esempio n. 1
0
        public static async Task ReadObjectAsync(BlittableJsonDocumentBuilder builder, PeepingTomStream peepingTomStream, UnmanagedJsonParser parser, JsonOperationContext.MemoryBuffer buffer, CancellationToken token = default)
        {
            builder.ReadNestedObject();
            while (builder.Read() == false)
            {
                var read = await peepingTomStream.ReadAsync(buffer.Memory.Memory, token).ConfigureAwait(false);

                if (read == 0)
                {
                    throw new EndOfStreamException("Stream ended without reaching end of json content");
                }

                parser.SetBuffer(buffer, 0, read);
            }
            builder.FinalizeDocument();
        }
Esempio n. 2
0
        public static async Task ReadObjectAsync(BlittableJsonDocumentBuilder builder, PeepingTomStream peepingTomStream, UnmanagedJsonParser parser, JsonOperationContext.ManagedPinnedBuffer buffer)
        {
            builder.ReadNestedObject();
            while (builder.Read() == false)
            {
                var read = await peepingTomStream.ReadAsync(buffer.Buffer.Array, buffer.Buffer.Offset, buffer.Length).ConfigureAwait(false);

                if (read == 0)
                {
                    throw new EndOfStreamException("Stream ended without reaching end of json content");
                }

                parser.SetBuffer(buffer, 0, read);
            }
            builder.FinalizeDocument();
        }
Esempio n. 3
0
        public static async Task <bool> ReadAsync(PeepingTomStream peepingTomStream, UnmanagedJsonParser parser, JsonParserState state, JsonOperationContext.MemoryBuffer buffer, CancellationToken token = default)
        {
            while (parser.Read() == false)
            {
                var read = await peepingTomStream.ReadAsync(buffer.Memory.Memory, token).ConfigureAwait(false);

                if (read == 0)
                {
                    if (state.CurrentTokenType != JsonParserToken.EndObject)
                    {
                        throw new EndOfStreamException("Stream ended without reaching end of json content");
                    }

                    return(false);
                }

                parser.SetBuffer(buffer, 0, read);
            }

            return(true);
        }
Esempio n. 4
0
        public static async Task <bool> ReadAsync(PeepingTomStream peepingTomStream, UnmanagedJsonParser parser, JsonParserState state, JsonOperationContext.ManagedPinnedBuffer buffer)
        {
            if (parser.Read())
            {
                return(true);
            }

            var read = await peepingTomStream.ReadAsync(buffer.Buffer.Array, buffer.Buffer.Offset, buffer.Length).ConfigureAwait(false);

            if (read == 0)
            {
                if (state.CurrentTokenType != JsonParserToken.EndObject)
                {
                    throw new EndOfStreamException("Stream ended without reaching end of json content");
                }

                return(false);
            }

            parser.SetBuffer(buffer, 0, read);
            return(parser.Read());
        }