Encodes a message using the specified frame parameters, and compressor :param msg: the message, typically of cassandra.protocol._MessageType, generated by the driver :param stream_id: protocol stream id for the frame header :param protocol_version: version for the f
(cls, msg, stream_id, protocol_version, compressor, allow_beta_protocol_version)
| 1108 | |
| 1109 | @classmethod |
| 1110 | def encode_message(cls, msg, stream_id, protocol_version, compressor, allow_beta_protocol_version): |
| 1111 | """ |
| 1112 | Encodes a message using the specified frame parameters, and compressor |
| 1113 | |
| 1114 | :param msg: the message, typically of cassandra.protocol._MessageType, generated by the driver |
| 1115 | :param stream_id: protocol stream id for the frame header |
| 1116 | :param protocol_version: version for the frame header, and used encoding contents |
| 1117 | :param compressor: optional compression function to be used on the body |
| 1118 | """ |
| 1119 | flags = 0 |
| 1120 | body = io.BytesIO() |
| 1121 | if msg.custom_payload: |
| 1122 | if protocol_version < 4: |
| 1123 | raise UnsupportedOperation("Custom key/value payloads can only be used with protocol version 4 or higher") |
| 1124 | flags |= CUSTOM_PAYLOAD_FLAG |
| 1125 | write_bytesmap(body, msg.custom_payload) |
| 1126 | msg.send_body(body, protocol_version) |
| 1127 | body = body.getvalue() |
| 1128 | |
| 1129 | # With checksumming, the compression is done at the segment frame encoding |
| 1130 | if (not ProtocolVersion.has_checksumming_support(protocol_version) |
| 1131 | and compressor and len(body) > 0): |
| 1132 | body = compressor(body) |
| 1133 | flags |= COMPRESSED_FLAG |
| 1134 | |
| 1135 | if msg.tracing: |
| 1136 | flags |= TRACING_FLAG |
| 1137 | |
| 1138 | if allow_beta_protocol_version: |
| 1139 | flags |= USE_BETA_FLAG |
| 1140 | |
| 1141 | buff = io.BytesIO() |
| 1142 | cls._write_header(buff, protocol_version, flags, stream_id, msg.opcode, len(body)) |
| 1143 | buff.write(body) |
| 1144 | |
| 1145 | return buff.getvalue() |
| 1146 | |
| 1147 | @staticmethod |
| 1148 | def _write_header(f, version, flags, stream_id, opcode, length): |
nothing calls this directly
no test coverage detected