MCPcopy
hub / github.com/pika/pika / encode_table

Function encode_table

pika/data.py:59–78  ·  view source on GitHub ↗

Encode a dict as an AMQP table appending the encded table to the pieces list passed in. :param list pieces: Already encoded frame pieces :param dict table: The dict to encode :rtype: int

(pieces: List[bytes], table: Optional[Dict[str, Any]])

Source from the content-addressed store, hash-verified

57
58
59def encode_table(pieces: List[bytes], table: Optional[Dict[str, Any]]) -> int:
60 """Encode a dict as an AMQP table appending the encded table to the
61 pieces list passed in.
62
63 :param list pieces: Already encoded frame pieces
64 :param dict table: The dict to encode
65 :rtype: int
66
67 """
68 table = table or {}
69 length_index = len(pieces)
70 # placeholder overwritten by pieces[length_index] below
71 pieces.append(None) # type: ignore[arg-type]
72 tablesize = 0
73 for (key, value) in table.items():
74 tablesize += encode_short_string(pieces, key)
75 tablesize += encode_value(pieces, value)
76
77 pieces[length_index] = struct.pack('>I', tablesize)
78 return tablesize + 4
79
80
81def encode_value(pieces: List[bytes], value: Any) -> int: # pylint: disable=R0911

Callers 1

encode_valueFunction · 0.85

Calls 2

encode_short_stringFunction · 0.85
encode_valueFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…