예제 #1
0
 private byte[] serializeForDynamicType(params object[] vals)
 {
     var elt = new FrameWriter(new MemoryStream());
     foreach (object p in vals)
     {
         if (p is int)
         {
             elt.WriteUInt16(0x8000 | 'i');
             elt.WriteUInt16(4);
             elt.WriteInt32((int)p);
             elt.WriteByte(0);
         }
         else if (p is String)
         {
             elt.WriteUInt16(0x8000 | 's');
             elt.WriteString(p as string);
             elt.WriteByte(0);
         }
         else
         {
             throw new InvalidOperationException();
         }
     }
     var ret = new byte[elt.Length];
     Buffer.BlockCopy(elt.GetBuffer(), 0, ret, 0, (int)elt.Length);
     return ret;
 }
예제 #2
0
 public void WriteToBatch(FrameWriter wb)
 {
     wb.WriteByte(1); //prepared query
     wb.WriteShortBytes(_id);
     wb.WriteUInt16((ushort)_queryOptions.Values.Length);
     foreach (var queryParameter in _queryOptions.Values)
     {
         wb.WriteAsBytes(queryParameter);
     }
 }
예제 #3
0
        protected override void WriteBody(FrameWriter wb)
        {
            var protocolVersion = wb.Serializer.ProtocolVersion;

            wb.WriteByte((byte)_type);
            wb.WriteUInt16((ushort)_requests.Count);

            foreach (var br in _requests)
            {
                br.WriteToBatch(wb);
            }

            wb.WriteUInt16((ushort)Consistency);

            if (!protocolVersion.SupportsBatchFlags())
            {
                // if the protocol version doesn't support flags,
                // then it doesn't support the following optional parameters either
                return;
            }

            if (protocolVersion.Uses4BytesQueryFlags())
            {
                wb.WriteInt32((int)_batchFlags);
            }
            else
            {
                wb.WriteByte((byte)_batchFlags);
            }

            // this is optional in the protocol but we always set it
            wb.WriteUInt16((ushort)SerialConsistency);

            if (protocolVersion.SupportsTimestamp() && _timestamp != null)
            {
                wb.WriteLong(_timestamp.Value);
            }

            if (protocolVersion.SupportsKeyspaceInRequest() && _keyspace != null)
            {
                wb.WriteString(_keyspace);
            }
        }
예제 #4
0
 public void WriteToBatch(byte protocolVersion, FrameWriter wb)
 {
     wb.WriteByte(1); //prepared query
     wb.WriteShortBytes(_id);
     wb.WriteUInt16((ushort)_queryOptions.Values.Length);
     for (int i = 0; i < _metadata.Columns.Length; i++)
     {
         byte[] bytes = TypeCodec.Encode(protocolVersion, _queryOptions.Values[i]);
         wb.WriteBytes(bytes);
     }
 }
        public int WriteFrame(short streamId, MemoryStream stream, Serializer serializer)
        {
            //protocol v2: <type><n><query_1>...<query_n><consistency>
            //protocol v3: <type><n><query_1>...<query_n><consistency><flags>[<serial_consistency>][<timestamp>]
            var protocolVersion = serializer.ProtocolVersion;
            var wb = new FrameWriter(stream, serializer);

            if (Payload != null)
            {
                _headerFlags |= FrameHeader.HeaderFlag.CustomPayload;
            }
            wb.WriteFrameHeader((byte)_headerFlags, streamId, OpCode);
            if (Payload != null)
            {
                //A custom payload for this request
                wb.WriteBytesMap(Payload);
            }
            wb.WriteByte((byte)_type);
            wb.WriteInt16((short)_requests.Count);
            foreach (var br in _requests)
            {
                br.WriteToBatch(wb);
            }
            wb.WriteInt16((short)Consistency);
            if (protocolVersion >= 3)
            {
                wb.WriteByte((byte)_batchFlags);
            }
            if (_serialConsistency != null)
            {
                wb.WriteInt16((short)_serialConsistency.Value);
            }
            if (_timestamp != null)
            {
                //Expressed in microseconds
                wb.WriteLong(TypeSerializer.SinceUnixEpoch(_timestamp.Value).Ticks / 10);
            }
            return(wb.Close());
        }
예제 #6
0
 public void WriteToBatch(FrameWriter wb)
 {
     //not a prepared query
     wb.WriteByte(0);
     wb.WriteLongString(_cqlQuery);
     if (_queryOptions.Values == null || _queryOptions.Values.Length == 0)
     {
         // No values
         wb.WriteUInt16(0);
     }
     else
     {
         wb.WriteUInt16((ushort)_queryOptions.Values.Length);
         foreach (var queryParameter in _queryOptions.Values)
         {
             wb.WriteAsBytes(queryParameter);
         }
     }
 }
예제 #7
0
 public void WriteToBatch(byte protocolVersion, FrameWriter wb)
 {
     //not a prepared query
     wb.WriteByte(0);
     wb.WriteLongString(_cqlQuery);
     if (_queryOptions.Values == null || _queryOptions.Values.Length == 0)
     {
         //not values
         wb.WriteInt16(0);
     }
     else
     {
         wb.WriteUInt16((ushort)_queryOptions.Values.Length);
         for (var i = 0; i < _queryOptions.Values.Length; i++)
         {
             var bytes = TypeCodec.Encode(protocolVersion, _queryOptions.Values[i]);
             wb.WriteBytes(bytes);
         }
     }
 }
예제 #8
0
 public void WriteToBatch(byte protocolVersion, FrameWriter wb)
 {
     wb.WriteByte(1); //prepared query
     wb.WriteShortBytes(_id);
     wb.WriteUInt16((ushort) _queryOptions.Values.Length);
     for (int i = 0; i < _metadata.Columns.Length; i++)
     {
         byte[] bytes = TypeCodec.Encode(protocolVersion, _queryOptions.Values[i]);
         wb.WriteBytes(bytes);
     }
 }
예제 #9
0
 public void WriteToBatch(byte protocolVersion, FrameWriter wb)
 {
     //not a prepared query
     wb.WriteByte(0);
     wb.WriteLongString(_cqlQuery);
     if (_queryOptions.Values == null || _queryOptions.Values.Length == 0)
     {
         //not values
         wb.WriteInt16(0);
     }
     else
     {
         wb.WriteUInt16((ushort) _queryOptions.Values.Length);
         for (var i = 0; i < _queryOptions.Values.Length; i++)
         {
             var bytes = TypeCodec.Encode(protocolVersion, _queryOptions.Values[i]);
             wb.WriteBytes(bytes);
         }
     }
 }
예제 #10
0
 public int WriteFrame(short streamId, MemoryStream stream)
 {
     //protocol v2: <type><n><query_1>...<query_n><consistency>
     //protocol v3: <type><n><query_1>...<query_n><consistency><flags>[<serial_consistency>][<timestamp>]
     var wb = new FrameWriter(stream);
     if (Payload != null)
     {
         _headerFlags |= FrameHeader.HeaderFlag.CustomPayload;
     }
     wb.WriteFrameHeader((byte)ProtocolVersion, (byte)_headerFlags, streamId, OpCode);
     if (Payload != null)
     {
         //A custom payload for this request
         wb.WriteBytesMap(Payload);
     }
     wb.WriteByte((byte) _type);
     wb.WriteInt16((short) _requests.Count);
     foreach (var br in _requests)
     {
         br.WriteToBatch((byte)ProtocolVersion, wb);
     }
     wb.WriteInt16((short) Consistency);
     if (ProtocolVersion >= 3)
     {
         wb.WriteByte((byte)_batchFlags);
     }
     if (_serialConsistency != null)
     {
         wb.WriteInt16((short)_serialConsistency.Value);
     }
     if (_timestamp != null)
     {
         //Expressed in microseconds
         wb.WriteLong(TypeCodec.ToUnixTime(_timestamp.Value).Ticks / 10);
     }
     return wb.Close();
 }
예제 #11
0
 public void WriteToBatch(FrameWriter wb)
 {
     //not a prepared query
     wb.WriteByte(0);
     wb.WriteLongString(_cqlQuery);
     if (_queryOptions.Values == null || _queryOptions.Values.Length == 0)
     {
         //not values
         wb.WriteInt16(0);
     }
     else
     {
         wb.WriteUInt16((ushort) _queryOptions.Values.Length);
         foreach (var queryParameter in _queryOptions.Values)
         {
             wb.WriteAsBytes(queryParameter);
         }
     }
 }
예제 #12
0
 public void WriteToBatch(FrameWriter wb)
 {
     wb.WriteByte(1); //prepared query
     wb.WriteShortBytes(_id);
     wb.WriteUInt16((ushort)_queryOptions.Values.Length);
     foreach (var queryParameter in _queryOptions.Values)
     {
         wb.WriteAsBytes(queryParameter);
     }
 }
예제 #13
0
        // Test a wide row consisting of a ByteBuffer
        private static void TestByteRows(ISession session, string tableName)
        {
            session.Execute(String.Format("CREATE TABLE {0} (k INT, i {1}, PRIMARY KEY(k,i))", tableName, "BLOB"));

            // Build small ByteBuffer sample
            var bw = new FrameWriter(new MemoryStream());
            for (int i = 0; i < 56; i++)
                bw.WriteByte(0);
            bw.WriteUInt16(0xCAFE);
            var bb = new byte[58];
            Array.Copy(bw.GetBuffer(), bb, 58);

            // Write data
            for (int i = 0; i < 1024; ++i)
                session.Execute(string.Format("INSERT INTO {0}(k,i) values({1},0x{2})", tableName, Key, CqlQueryTools.ToHex(bb)),
                                ConsistencyLevel.Quorum);

            // Read data
            var rs = session.Execute("SELECT i FROM " + tableName + " WHERE k = " + Key, ConsistencyLevel.Quorum);
            // Verify data            
            foreach (var row in rs)
                Assert.AreEqual((byte[])row["i"], bb);
        }