public void BeBinaryWriter_Close_Sets_Frame_Body_Length() { const int frameLength = 10; const int iterations = 8; const byte protocolVersion = 2; var bufferPool = new RecyclableMemoryStreamManager(); using (var stream = bufferPool.GetStream("test")) { for (var i = 0; i < iterations; i++) { var writer = new FrameWriter(stream, new Serializer(protocolVersion)); writer.WriteFrameHeader(0, 127, 8); writer.WriteInt16(Convert.ToInt16(0x0900 + i)); var length = writer.Close(); Assert.AreEqual(frameLength, length); } Assert.AreEqual(frameLength * iterations, stream.Length); for (byte i = 0; i < iterations; i++) { var buffer = new byte[frameLength]; stream.Position = i * frameLength; stream.Read(buffer, 0, frameLength); CollectionAssert.AreEqual(new byte[] { 2, 0, 127, 8, 0, 0, 0, 2, 9, i }, buffer); } } }
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()); }
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); } } }
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); } } }
public void BeBinaryWriter_Close_Sets_Frame_Body_Length() { const int frameLength = 10; const int iterations = 8; var bufferPool = new RecyclableMemoryStreamManager(); using (var stream = bufferPool.GetStream("test")) { for (var i = 0; i < iterations; i++) { var writer = new FrameWriter(stream); writer.WriteFrameHeader(2, 0, 127, 8); writer.WriteInt16(Convert.ToInt16(0x0900 + i)); var length = writer.Close(); Assert.AreEqual(frameLength, length); } Assert.AreEqual(frameLength * iterations, stream.Length); for (byte i = 0; i < iterations; i++) { var buffer = new byte[frameLength]; stream.Position = i * frameLength; stream.Read(buffer, 0, frameLength); CollectionAssert.AreEqual(new byte[] { 2, 0, 127, 8, 0, 0, 0, 2, 9, i}, buffer); } } }
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); } } }
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(); }
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); } } }