Example #1
0
 protected override void WriteData(Stream buffer)
 {
     buffer.WriteShortByteArray(QueryId);
     buffer.WriteShort((short)Parameters.Count);
     foreach (var prm in Parameters)
         buffer.WriteByteArray(prm);
     buffer.WriteShort((short)CqlConsistency);
 }
Example #2
0
        /// <summary>
        /// Writes the data to buffer.
        /// </summary>
        /// <param name="buffer"> The buffer. </param>
        protected override void WriteData(Stream buffer)
        {
            if(ProtocolVersion == 1)
            {
                throw new ProtocolException(ProtocolVersion, ErrorCode.Protocol, "Batch frames are supported from Cassandra Version 2.0.0 and up.");
            }

            buffer.WriteByte((byte)Type);
            buffer.WriteShort((ushort)Commands.Count);
            foreach(var command in Commands)
            {
                if(command.IsPrepared)
                {
                    buffer.WriteByte(1);
                    buffer.WriteShortByteArray(command.QueryId);
                }
                else
                {
                    buffer.WriteByte(0);
                    buffer.WriteLongString(command.CqlQuery);
                }

                if(command.ParameterValues != null)
                {
                    byte[][] paramValues = command.ParameterValues.Serialize(ProtocolVersion);
                    var length = (ushort)paramValues.Length;
                    buffer.WriteShort(length);
                    for(var i = 0; i < length; i++)
                    {
                        buffer.WriteByteArray(paramValues[i]);
                    }
                }
                else
                    buffer.WriteShort(0);
            }

            buffer.WriteConsistency(CqlConsistency);

            if(ProtocolVersion >= 3)
            {
                var flags = (byte)((SerialConsistency.HasValue ? 16 : 0) |
                                   (Timestamp.HasValue ? 32 : 0));

                buffer.WriteByte(flags);

                if(SerialConsistency.HasValue)
                    buffer.WriteShort((ushort)SerialConsistency.Value);

                if(Timestamp.HasValue)
                    buffer.WriteLong(Timestamp.Value.ToTimestamp());
            }
        }
Example #3
0
        /// <summary>
        /// Writes the query parameters.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        protected void WriteQueryParameters(Stream buffer)
        {
            buffer.WriteConsistency(CqlConsistency);

            var flags = (byte)((Parameters != null ? 1 : 0) |
                               (SkipMetaData ? 2 : 0) |
                               (PageSize.HasValue ? 4 : 0) |
                               (PagingState != null ? 8 : 0) |
                               (SerialConsistency.HasValue ? 16 : 0) |
                               (ProtocolVersion >= 3 && Timestamp.HasValue ? 32 : 0));

            buffer.WriteByte(flags);

            if(Parameters != null)
            {
                buffer.WriteShort((ushort)Parameters.Count);
                foreach(var value in Parameters)
                    buffer.WriteByteArray(value);
            }

            if(PageSize.HasValue)
                buffer.WriteInt(PageSize.Value);

            if(PagingState != null)
                buffer.WriteByteArray(PagingState);

            if(SerialConsistency.HasValue)
                buffer.WriteShort((ushort)SerialConsistency.Value);

            if(ProtocolVersion >= 3 && Timestamp.HasValue)
                buffer.WriteLong(Timestamp.Value.ToTimestamp()*1000); //convert milliseconds to microseconds
        }
Example #4
0
 protected override void WriteData(Stream buffer)
 {
     buffer.WriteByteArray(SaslResponse);
 }