| 301 | |
| 302 | |
| 303 | class GetDataMessage: |
| 304 | command = b'getdata' |
| 305 | |
| 306 | def __init__(self): |
| 307 | self.data = [] |
| 308 | |
| 309 | def add_data(self, data_type, identifier): |
| 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 | |
| 324 | class GetDataMessageTest(TestCase): |