MCPcopy Index your code
hub / github.com/jimmysong/programmingbitcoin / serialize

Method serialize

code-ch13/network.py:312–321  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

310 self.data.append((data_type, identifier))
311
312 def serialize(self):
313 # start with the number of items as a varint
314 result = encode_varint(len(self.data))
315 # loop through each tuple (data_type, identifier) in self.data
316 for data_type, identifier in self.data:
317 # data type is 4 bytes Little-Endian
318 result += int_to_little_endian(data_type, 4)
319 # identifier needs to be in Little-Endian
320 result += identifier[::-1]
321 return result
322
323
324class GetDataMessageTest(TestCase):

Callers 1

test_serializeMethod · 0.95

Calls 2

encode_varintFunction · 0.90
int_to_little_endianFunction · 0.90

Tested by 1

test_serializeMethod · 0.76