public void Write_List_And_Tuple()
        {
            byte[] want = new byte[]
            {
                131, 108, 0, 0, 0, 2, 104, 2, 100, 0, 4, 116, 114, 117, 101, 100, 0, 5,
                102, 97, 108, 115, 101, 108, 0, 0, 0, 2, 100, 0, 4, 116, 114, 117, 101,
                100, 0, 5, 102, 97, 108, 115, 101, 106, 106
            };
            byte[] got;
            using (var os = new OtpOutputStream())
            {
                os.WriteByte(OtpExternal.VersionTag);
                os.WriteListHead(2);
                os.WriteTupleHead(2);
                os.WriteBoolean(true);
                os.WriteBoolean(false);
                os.WriteListHead(2);
                os.WriteBoolean(true);
                os.WriteBoolean(false);
                os.WriteNil();
                os.WriteNil();
                Assert.AreEqual(want.Length, os.Position);
                got = os.ToArray();
            }

            CollectionAssert.AreEqual(want, got);
        }
Beispiel #2
0
        internal void ToTtbCell(OtpOutputStream os)
        {
            if (isNull)
            {
                os.WriteNil();
                return;
            }

            if (valueType == ColumnType.Varchar || valueType == ColumnType.Blob)
            {
                os.WriteBinary(varcharValue);
            }
            else if (valueType == ColumnType.SInt64)
            {
                os.WriteLong(sint64Value);
            }
            else if (valueType == ColumnType.Timestamp)
            {
                os.WriteLong(timestampValue);
            }
            else if (valueType == ColumnType.Boolean)
            {
                os.WriteBoolean(booleanValue);
            }
            else if (valueType == ColumnType.Double)
            {
                os.WriteDouble(doubleValue);
            }
            else
            {
                throw new InvalidOperationException("Could not convert to TTB value.");
            }
        }
        public void Write_Boolean(bool b, byte[] want)
        {
            byte[] got;
            using (var os = new OtpOutputStream())
            {
                os.Write(OtpExternal.VersionTag);
                os.WriteBoolean(b);
                Assert.AreEqual(want.Length, os.Position);
                got = os.ToArray();
            }

            CollectionAssert.AreEqual(want, got);
        }
Beispiel #4
0
        public override RiakReq ConstructRequest(bool useTtb)
        {
            if (useTtb)
            {
                expectedCode = MessageCode.TsTtbMsg;
                usingTtb     = true;

                using (var os = new OtpOutputStream())
                {
                    os.WriteByte(OtpExternal.VersionTag);

                    // TsQueryReq is a 4-tuple: {'tsqueryreq', TsInterpolation, boolIsStreaming, bytesCoverContext}
                    os.WriteTupleHead(4);
                    os.WriteAtom(TsQueryReqAtom);

                    // TsInterpolation is a 3-tuple
                    // {'tsinterpolation', query, []} empty list is interpolations
                    os.WriteTupleHead(3);
                    os.WriteAtom(TsInterpolationAtom);
                    os.WriteStringAsBinary(CommandOptions.Query);
                    os.WriteNil();

                    os.WriteBoolean(false);
                    os.WriteAtom(UndefinedAtom);
                    os.Flush();

                    return(new TsTtbMsg(os.ToArray()));
                }
            }
            else
            {
                var req = new TsQueryReq();

                req.query = new TsInterpolation
                {
                    @base = CommandOptions.Query
                };

                // NB: always stream, collect results unless callback is passed.
                req.stream = true;

                return(req);
            }
        }