def send_body(self, f, protocol_version): write_longstring(f, self.query) flags = 0x00 if self.keyspace is not None: if ProtocolVersion.uses_keyspace_flag(protocol_version): flags |= _PREPARED_WITH_KEYSPACE_FLAG else: raise UnsupportedOperation( "Keyspaces may only be set on queries with protocol version " "DSE_V2 or higher. Consider setting Cluster.protocol_version to ProtocolVersion.DSE_V2." ) if ProtocolVersion.uses_prepare_flags(protocol_version): write_uint(f, flags) else: # checks above should prevent this, but just to be safe... if flags: raise UnsupportedOperation( "Attempted to set flags with value {flags:0=#8x} on" "protocol version {pv}, which doesn't support flags" "in prepared statements." "Consider setting Cluster.protocol_version to ProtocolVersion.DSE_V2." "".format(flags=flags, pv=protocol_version)) if ProtocolVersion.uses_keyspace_flag(protocol_version): if self.keyspace: write_string(f, self.keyspace)
def send_body(self, f, protocol_version): write_int(f, self.op_type) write_int(f, self.op_id) if self.op_type == ReviseRequestMessage.RevisionType.PAGING_BACKPRESSURE: if self.next_pages <= 0: raise UnsupportedOperation( "Continuous paging backpressure requires next_pages > 0") elif not ProtocolVersion.has_continuous_paging_next_pages( protocol_version): raise UnsupportedOperation( "Continuous paging backpressure may only be used with protocol version " "ProtocolVersion.DSE_V2 or higher. Consider setting Cluster.protocol_version to ProtocolVersion.DSE_V2." ) else: write_int(f, self.next_pages)
def encode_message(cls, msg, stream_id, protocol_version, compressor, allow_beta_protocol_version): """ Encodes a message using the specified frame parameters, and compressor :param msg: the message, typically of dse.protocol._MessageType, generated by the driver :param stream_id: protocol stream id for the frame header :param protocol_version: version for the frame header, and used encoding contents :param compressor: optional compression function to be used on the body """ flags = 0 body = io.BytesIO() if msg.custom_payload: if protocol_version < 4: raise UnsupportedOperation("Custom key/value payloads can only be used with protocol version 4 or higher") flags |= CUSTOM_PAYLOAD_FLAG write_bytesmap(body, msg.custom_payload) msg.send_body(body, protocol_version) body = body.getvalue() if compressor and len(body) > 0: body = compressor(body) flags |= COMPRESSED_FLAG if msg.tracing: flags |= TRACING_FLAG if allow_beta_protocol_version: flags |= USE_BETA_FLAG buff = io.BytesIO() cls._write_header(buff, protocol_version, flags, stream_id, msg.opcode, len(body)) buff.write(body) return buff.getvalue()
def _write_query_params(self, f, protocol_version): write_consistency_level(f, self.consistency_level) flags = 0x00 if self.query_params is not None: flags |= _VALUES_FLAG if self.serial_consistency_level: flags |= _WITH_SERIAL_CONSISTENCY_FLAG if self.fetch_size: flags |= _PAGE_SIZE_FLAG if self.continuous_paging_options and self.continuous_paging_options.page_unit_bytes(): flags |= _PAGE_SIZE_BYTES_FLAG if self.paging_state: flags |= _WITH_PAGING_STATE_FLAG if self.timestamp is not None: flags |= _PROTOCOL_TIMESTAMP_FLAG if self.continuous_paging_options: if ProtocolVersion.has_continuous_paging_support(protocol_version): flags |= _PAGING_OPTIONS_FLAG else: raise UnsupportedOperation( "Continuous paging may only be used with protocol version " "ProtocolVersion.DSE_V1 or higher. Consider setting Cluster.protocol_version to ProtocolVersion.DSE_V1.") if ProtocolVersion.uses_int_query_flags(protocol_version): write_uint(f, flags) else: write_byte(f, flags) if self.query_params is not None: write_short(f, len(self.query_params)) for param in self.query_params: write_value(f, param) if self.fetch_size: write_int(f, self.fetch_size) if self.paging_state: write_longstring(f, self.paging_state) if self.serial_consistency_level: write_consistency_level(f, self.serial_consistency_level) if self.timestamp is not None: write_long(f, self.timestamp) if self.continuous_paging_options: self._write_paging_options(f, self.continuous_paging_options)
def send_body(self, f, protocol_version): write_byte(f, self.batch_type.value) write_short(f, len(self.queries)) for prepared, string_or_query_id, params in self.queries: if not prepared: write_byte(f, 0) write_longstring(f, string_or_query_id) else: write_byte(f, 1) write_short(f, len(string_or_query_id)) f.write(string_or_query_id) write_short(f, len(params)) for param in params: write_value(f, param) write_consistency_level(f, self.consistency_level) flags = 0 if self.serial_consistency_level: flags |= _WITH_SERIAL_CONSISTENCY_FLAG if self.timestamp is not None: flags |= _PROTOCOL_TIMESTAMP_FLAG if self.keyspace: if ProtocolVersion.uses_keyspace_flag(protocol_version): flags |= _WITH_KEYSPACE_FLAG else: raise UnsupportedOperation( "Keyspaces may only be set on queries with protocol version " "DSE_V2 or higher. Consider setting Cluster.protocol_version to ProtocolVersion.DSE_V2." ) if ProtocolVersion.uses_int_query_flags(protocol_version): write_uint(f, flags) else: write_byte(f, flags) if self.serial_consistency_level: write_consistency_level(f, self.serial_consistency_level) if self.timestamp is not None: write_long(f, self.timestamp) if ProtocolVersion.uses_keyspace_flag(protocol_version): if self.keyspace is not None: write_string(f, self.keyspace)