コード例 #1
0
        public ResponseDecoder(TsTtbResp response)
        {
            using (var s = new OtpInputStream(response.Response))
            {
                byte tag = s.Read1();
                if (tag != OtpExternal.VersionTag)
                {
                    string msg = string.Format(
                        "Expected OTP input stream to start with {0}, got {1}",
                        OtpExternal.VersionTag,
                        tag);
                    throw new InvalidOperationException(msg);
                }

                tag = s.Peek();
                switch (tag)
                {
                case OtpExternal.AtomTag:
                    string atom = s.ReadAtom();
                    decodedResponse = ParseAtomResult(atom);
                    break;

                case OtpExternal.SmallTupleTag:
                case OtpExternal.LargeTupleTag:
                    decodedResponse = ParseTupleResult(s);
                    break;

                default:
                    throw new InvalidOperationException("Expected an atom or tuple.");
                }
            }
        }
コード例 #2
0
        public override void OnSuccess(RpbResp response)
        {
            var             decoder = new ResponseDecoder((TsGetResp)response);
            DecodedResponse dr      = decoder.Decode();

            Response = new GetResponse(CommandOptions.Key, dr.Columns, dr.Rows);
        }
コード例 #3
0
        public ResponseDecoder(TsTtbResp response)
        {
            using (var s = new OtpInputStream(response.Response))
            {
                byte tag = s.Read1();
                if (tag != OtpExternal.VersionTag)
                {
                    string msg = string.Format(
                        "Expected OTP input stream to start with {0}, got {1}",
                        OtpExternal.VersionTag,
                        tag);
                    throw new InvalidOperationException(msg);
                }

                tag = s.Peek();
                switch (tag)
                {
                    case OtpExternal.AtomTag:
                        string atom = s.ReadAtom();
                        decodedResponse = ParseAtomResult(atom);
                        break;
                    case OtpExternal.SmallTupleTag:
                    case OtpExternal.LargeTupleTag:
                        decodedResponse = ParseTupleResult(s);
                        break;
                    default:
                        throw new InvalidOperationException("Expected an atom or tuple.");
                }
            }
        }
コード例 #4
0
        private ResponseDecoder(
            IEnumerable <TsColumnDescription> tscols,
            IEnumerable <TsRow> tsrows)
        {
            IEnumerable <Column> cols = Enumerable.Empty <Column>();

            if (EnumerableUtil.NotNullOrEmpty(tscols))
            {
                cols = tscols.Select(tsc =>
                                     new Column(RiakString.FromBytes(tsc.name), (ColumnType)tsc.type));
            }

            IEnumerable <Row> rows = Enumerable.Empty <Row>();

            if (EnumerableUtil.NotNullOrEmpty(tsrows))
            {
                rows = tsrows.Select(tsr => new Row(tsr, tscols.ToArray()));
            }

            decodedResponse = new DecodedResponse(cols, rows);
        }
コード例 #5
0
        private ResponseDecoder(
            IEnumerable<TsColumnDescription> tscols,
            IEnumerable<TsRow> tsrows)
        {
            IEnumerable<Column> cols = Enumerable.Empty<Column>();

            if (EnumerableUtil.NotNullOrEmpty(tscols))
            {
                cols = tscols.Select(tsc =>
                    new Column(RiakString.FromBytes(tsc.name), (ColumnType)tsc.type));
            }

            IEnumerable<Row> rows = Enumerable.Empty<Row>();

            if (EnumerableUtil.NotNullOrEmpty(tsrows))
            {
                rows = tsrows.Select(tsr => new Row(tsr, tscols.ToArray()));
            }

            decodedResponse = new DecodedResponse(cols, rows);
        }
コード例 #6
0
        public override void OnSuccess(RpbResp response)
        {
            var             decoder = new ResponseDecoder((TsQueryResp)response);
            DecodedResponse dr      = decoder.Decode();

            Response = new QueryResponse(CommandOptions.Query, dr.Columns, dr.Rows);

            if (CommandOptions.Callback != null)
            {
                CommandOptions.Callback(Response);
            }
            else
            {
                rows.AddRange(Response.Value);
            }

            var streamingResponse = response as IRpbStreamingResp;

            if (streamingResponse != null && streamingResponse.done)
            {
                Response = new QueryResponse(CommandOptions.Query, dr.Columns, rows);
            }
        }