예제 #1
0
 public GraphBinaryMessageSerializer(GraphBinaryReader reader, GraphBinaryWriter writer)
 {
     _reader = reader;
     _writer = writer;
 }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GraphBinaryMessageSerializer" /> class.
 /// </summary>
 /// <param name="reader">The <see cref="GraphBinaryReader"/> used to deserialize from GraphBinary.</param>
 /// <param name="writer">The <see cref="GraphBinaryWriter"/> used to serialize to GraphBinary.</param>
 public GraphBinaryMessageSerializer(GraphBinaryReader reader = null, GraphBinaryWriter writer = null)
 {
     _reader = reader ?? new GraphBinaryReader();
     _writer = writer ?? new GraphBinaryWriter();
 }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GraphBinaryMessageSerializer" /> class.
 /// </summary>
 /// <param name="registry">The <see cref="TypeSerializerRegistry"/> to use for serialization.</param>
 public GraphBinaryMessageSerializer(TypeSerializerRegistry registry = null)
 {
     _reader = new GraphBinaryReader(registry);
     _writer = new GraphBinaryWriter(registry);
 }
예제 #4
0
        /// <summary>
        /// Reads a response message from the stream.
        /// </summary>
        /// <param name="stream">The GraphBinary data to parse.</param>
        /// <param name="reader">A <see cref="GraphBinaryReader"/> that can be used to read nested values.</param>
        /// <returns>The read response message.</returns>
        public async Task <ResponseMessage <List <object> > > ReadValueAsync(MemoryStream stream, GraphBinaryReader reader)
        {
            var version = await stream.ReadByteAsync().ConfigureAwait(false) & 0xff;

            if (version >> 7 != 1)
            {
                // This is an indication that the response stream was incorrectly built
                // Or the stream offsets are wrong
                throw new IOException("The most significant bit should be set according to the format");
            }

            var requestId = (Guid?)await reader.ReadValueAsync <Guid>(stream, true).ConfigureAwait(false);

            var code = (ResponseStatusCode)await reader.ReadValueAsync <int>(stream, false).ConfigureAwait(false);

            var message = (string)await reader.ReadValueAsync <string>(stream, true).ConfigureAwait(false);

            var dictObj = await reader
                          .ReadValueAsync <Dictionary <string, object> >(stream, false).ConfigureAwait(false);

            var attributes = (Dictionary <string, object>)dictObj;

            var status = new ResponseStatus
            {
                Code       = code,
                Message    = message,
                Attributes = attributes
            };
            var result = new ResponseResult <List <object> >
            {
                Meta = (Dictionary <string, object>) await reader
                       .ReadValueAsync <Dictionary <string, object> >(stream, false).ConfigureAwait(false),
                Data = (List <object>) await reader.ReadAsync(stream).ConfigureAwait(false)
            };

            return(new ResponseMessage <List <object> >
            {
                RequestId = requestId,
                Status = status,
                Result = result
            });
        }