MCPcopy Index your code
hub / github.com/miguelgrinberg/python-socketio / encode

Method encode

src/socketio/packet.py:45–67  ·  view source on GitHub ↗

Encode the packet for transmission. If the packet contains binary elements, this function returns a list of packets where the first is the original packet with placeholders for the binary components and the remaining ones the binary attachments.

(self)

Source from the content-addressed store, hash-verified

43 self.attachment_count = self.decode(encoded_packet) or 0
44
45 def encode(self):
46 """Encode the packet for transmission.
47
48 If the packet contains binary elements, this function returns a list
49 of packets where the first is the original packet with placeholders for
50 the binary components and the remaining ones the binary attachments.
51 """
52 encoded_packet = str(self.packet_type)
53 if self.packet_type == BINARY_EVENT or self.packet_type == BINARY_ACK:
54 data, attachments = self.deconstruct_binary(self.data)
55 encoded_packet += str(len(attachments)) + '-'
56 else:
57 data = self.data
58 attachments = None
59 if self.namespace is not None and self.namespace != '/':
60 encoded_packet += self.namespace + ','
61 if self.id is not None:
62 encoded_packet += str(self.id)
63 if data is not None:
64 encoded_packet += self.json.dumps(data, separators=(',', ':'))
65 if attachments is not None:
66 encoded_packet = [encoded_packet] + attachments
67 return encoded_packet
68
69 def decode(self, encoded_packet):
70 """Decode a transmitted package.

Callers 15

testFunction · 0.95
testFunction · 0.95
testFunction · 0.95
testFunction · 0.95
test_emit_namespaceMethod · 0.95
test_emit_binaryMethod · 0.95

Calls 2

deconstruct_binaryMethod · 0.95
dumpsMethod · 0.45

Tested by 15

test_emit_namespaceMethod · 0.76
test_emit_binaryMethod · 0.76
test_emit_not_binaryMethod · 0.76
test_callMethod · 0.76
test_disconnectMethod · 0.76