コード例 #1
0
        /// <summary>Read response from the network stream.</summary>
        /// <remarks>If the response contains payload portion, i.e. files, they are <b>not</b> read from the stream.
        /// It's caller's responsibility to iterate through <see cref="payload" /> values and read all the data before reusing the connection for other requests.</remarks>
        public static async Task <Response> receive(Stream connection)
        {
            // Receive into a buffer
            using (var buffer = await ResponseBuffer.receive(connection))
            {
                // Parse binary JSON from that buffer
                Hash          dict        = null;
                List <object> otherValues = null;
                var           parser      = new ResponseParser(buffer);

                foreach (object obj in parser.parse())
                {
                    switch (obj)
                    {
                    case Hash h:
                        if (null == dict)
                        {
                            dict = h;
                            break;
                        }
                        goto default;

                    default:
                        if (null == otherValues)
                        {
                            otherValues = new List <object>();
                        }
                        otherValues.Add(obj);
                        break;
                    }
                }
                // Return a new response object
                return(new Response(dict, parser.payloads, otherValues));
            }
        }
コード例 #2
0
 /// <summary>Construct from a downloaded buffer.</summary>
 public ResponseParser(ResponseBuffer response)
 {
     reader = response;
 }