Decode the value passed in returning the decoded value and the number of bytes read in addition to the starting offset. :param str encoded: The binary encoded data to decode :param int offset: The starting byte offset :rtype: tuple :raises: pika.exceptions.InvalidFieldTypeExcept
(encoded: bytes, offset: int)
| 165 | |
| 166 | |
| 167 | def decode_value(encoded: bytes, offset: int) -> Tuple[Any, int]: # pylint: disable=R0912,R0915 |
| 168 | """Decode the value passed in returning the decoded value and the number |
| 169 | of bytes read in addition to the starting offset. |
| 170 | |
| 171 | :param str encoded: The binary encoded data to decode |
| 172 | :param int offset: The starting byte offset |
| 173 | :rtype: tuple |
| 174 | :raises: pika.exceptions.InvalidFieldTypeException |
| 175 | |
| 176 | """ |
| 177 | # Slice to get bytes |
| 178 | kind = encoded[offset:offset + 1] |
| 179 | offset += 1 |
| 180 | |
| 181 | # Bool |
| 182 | if kind == b't': |
| 183 | value = struct.unpack_from('>B', encoded, offset)[0] |
| 184 | value = bool(value) |
| 185 | offset += 1 |
| 186 | |
| 187 | # Short-Short Int |
| 188 | elif kind == b'b': |
| 189 | value = struct.unpack_from('>b', encoded, offset)[0] |
| 190 | offset += 1 |
| 191 | |
| 192 | # Short-Short Unsigned Int |
| 193 | elif kind == b'B': |
| 194 | value = struct.unpack_from('>B', encoded, offset)[0] |
| 195 | offset += 1 |
| 196 | |
| 197 | # Short Int |
| 198 | elif kind == b'U': |
| 199 | value = struct.unpack_from('>h', encoded, offset)[0] |
| 200 | offset += 2 |
| 201 | |
| 202 | # Short Unsigned Int |
| 203 | elif kind == b'u': |
| 204 | value = struct.unpack_from('>H', encoded, offset)[0] |
| 205 | offset += 2 |
| 206 | |
| 207 | # Long Int |
| 208 | elif kind == b'I': |
| 209 | value = struct.unpack_from('>i', encoded, offset)[0] |
| 210 | offset += 4 |
| 211 | |
| 212 | # Long Unsigned Int |
| 213 | elif kind == b'i': |
| 214 | value = struct.unpack_from('>I', encoded, offset)[0] |
| 215 | offset += 4 |
| 216 | |
| 217 | # Long-Long Int |
| 218 | elif kind == b'L': |
| 219 | value = long(struct.unpack_from('>q', encoded, offset)[0]) |
| 220 | offset += 8 |
| 221 | |
| 222 | # Long-Long Int (both 'l' and 'L' are signed per RabbitMQ and the |
| 223 | # AMQP 0-9-1 errata; see rabbitmq/rabbitmq-server#1093) |
| 224 | elif kind == b'l': |
no test coverage detected
searching dependent graphs…