Esempio n. 1
0
        public int WriteFrame(short streamId, MemoryStream stream, ISerializer 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.WriteUInt16((ushort)_requests.Count);
            foreach (var br in _requests)
            {
                br.WriteToBatch(wb);
            }
            wb.WriteUInt16((ushort)Consistency);
            if (protocolVersion.SupportsTimestamp())
            {
                if (protocolVersion.Uses4BytesQueryFlags())
                {
                    wb.WriteInt32((int)_batchFlags);
                }
                else
                {
                    wb.WriteByte((byte)_batchFlags);
                }

                wb.WriteUInt16((ushort)SerialConsistency);

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

                if (_keyspace != null)
                {
                    wb.WriteString(_keyspace);
                }
            }
            return(wb.Close());
        }
Esempio n. 2
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);
            }
        }
        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());
        }
Esempio n. 4
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();
 }