public int WriteFrame(short streamId, MemoryStream stream, ISerializer serializer) { var wb = new FrameWriter(stream, serializer); wb.WriteFrameHeader((byte)_headerFlags, streamId, OpCode); var protocolVersion = serializer.ProtocolVersion; if (_payload != null) { wb.WriteBytesMap(_payload); } wb.WriteLongString(Query); if (protocolVersion.SupportsKeyspaceInRequest()) { wb.WriteInt32((int)_prepareFlags); if (Keyspace != null) { wb.WriteString(Keyspace); } } return(wb.Close()); }
private byte[] serializeForDynamicType(params object[] vals) { var elt = new FrameWriter(new MemoryStream(), new Serializer(ProtocolVersion.V1)); 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); }
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; }
protected override void WriteBody(FrameWriter wb) { wb.WriteLongString(Query); if (_prepareFlags != null) { wb.WriteInt32((int)_prepareFlags); if (_prepareFlags.Value.HasFlag(PrepareFlags.WithKeyspace)) { wb.WriteString(Keyspace); } } }
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()); }
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); } }