Exemplo n.º 1
0
        private static DecodedResponse ParseTupleResult(OtpInputStream s)
        {
            // Response is:
            // {'tsgetresp', {ColNames, ColTypes, Rows}}
            // {'tsqueryresp', {ColNames, ColTypes, Rows}}
            int arity = s.ReadTupleHead();

            if (arity != 2)
            {
                throw new InvalidOperationException("Expected response to be a 2-tuple");
            }

            string msg;
            string atom = s.ReadAtom();

            switch (atom)
            {
            case TsGetRespAtom:
            case TsQueryRespAtom:
                arity = s.ReadTupleHead();
                if (arity != 3)
                {
                    msg = string.Format(
                        "Second item in {0} response tuple must be a 3-tuple.",
                        atom);
                    throw new InvalidOperationException(msg);
                }

                Column[] cols = ParseColumns(s);
                Row[]    rows = ParseRows(s, cols);
                return(new DecodedResponse(cols, rows));

            default:
                msg = string.Format(
                    "Expected tsgetresp or tsqueryresp atom, got {0}",
                    atom);
                throw new InvalidOperationException(msg);
            }
        }
Exemplo n.º 2
0
 public override void OnSuccess(RiakResp response)
 {
     if (usingTtb)
     {
         var ttbresp = (TsTtbResp)response;
         using (var s = new OtpInputStream(ttbresp.Response))
         {
             s.ReadTupleHead();
             string atom = s.ReadAtom();
             if (atom.Equals(TsPutRespAtom) == false)
             {
                 throw new InvalidDataException(
                           string.Format("Expected {0}, got {1}", TsPutRespAtom, atom));
             }
         }
     }
     else
     {
         Response = new StoreResponse();
     }
 }
Exemplo n.º 3
0
        private static Row ParseRow(OtpInputStream s, Column[] cols)
        {
            int cellCount = s.ReadTupleHead();

            if (cellCount != cols.Length)
            {
                string msg = string.Format(
                    "Expected cell count {0} to equal column count {1}",
                    cellCount,
                    cols.Length);
                throw new InvalidOperationException(msg);
            }

            Cell[] cells = new Cell[cellCount];
            for (int i = 0; i < cellCount; i++)
            {
                cells[i] = ParseCell(s, i, cols);
            }

            return(new Row(cells));
        }
Exemplo n.º 4
0
        private static DecodedResponse ParseTupleResult(OtpInputStream s)
        {
            // Response is:
            // {'tsgetresp', {ColNames, ColTypes, Rows}}
            // {'tsqueryresp', {ColNames, ColTypes, Rows}}
            int arity = s.ReadTupleHead();
            if (arity != 2)
            {
                throw new InvalidOperationException("Expected response to be a 2-tuple");
            }

            string msg;
            string atom = s.ReadAtom();
            switch (atom)
            {
                case TsGetRespAtom:
                case TsQueryRespAtom:
                    arity = s.ReadTupleHead();
                    if (arity != 3)
                    {
                        msg = string.Format(
                            "Second item in {0} response tuple must be a 3-tuple.",
                            atom);
                        throw new InvalidOperationException(msg);
                    }

                    Column[] cols = ParseColumns(s);
                    Row[] rows = ParseRows(s, cols);
                    return new DecodedResponse(cols, rows);
                default:
                    msg = string.Format(
                        "Expected tsgetresp or tsqueryresp atom, got {0}",
                        atom);
                    throw new InvalidOperationException(msg);
            }
        }
Exemplo n.º 5
0
        private static Row ParseRow(OtpInputStream s, Column[] cols)
        {
            int cellCount = s.ReadTupleHead();
            if (cellCount != cols.Length)
            {
                string msg = string.Format(
                    "Expected cell count {0} to equal column count {1}",
                    cellCount,
                    cols.Length);
                throw new InvalidOperationException(msg);
            }

            Cell[] cells = new Cell[cellCount];
            for (int i = 0; i < cellCount; i++)
            {
                cells[i] = ParseCell(s, i, cols);
            }

            return new Row(cells);
        }