MCPcopy Index your code
hub / github.com/Bitmessage/PyBitmessage / decode_payload_content

Method decode_payload_content

src/network/bmproto.py:161–268  ·  view source on GitHub ↗
(self, pattern = "v")

Source from the content-addressed store, hash-verified

159 return Node(services, host, port)
160
161 def decode_payload_content(self, pattern = "v"):
162 # L = varint indicating the length of the next array
163 # l = varint indicating the length of the next item
164 # v = varint (or array)
165 # H = uint16
166 # I = uint32
167 # Q = uint64
168 # i = net_addr (without time and stream number)
169 # s = string
170 # 0-9 = length of the next item
171 # , = end of array
172
173 def decode_simple(self, char="v"):
174 if char == "v":
175 return self.decode_payload_varint()
176 if char == "i":
177 return self.decode_payload_node()
178 if char == "H":
179 self.payloadOffset += 2
180 return struct.unpack(">H", self.payload[self.payloadOffset-2:self.payloadOffset])[0]
181 if char == "I":
182 self.payloadOffset += 4
183 return struct.unpack(">I", self.payload[self.payloadOffset-4:self.payloadOffset])[0]
184 if char == "Q":
185 self.payloadOffset += 8
186 return struct.unpack(">Q", self.payload[self.payloadOffset-8:self.payloadOffset])[0]
187
188 size = None
189 isArray = False
190
191 # size
192 # iterator starting from size counting to 0
193 # isArray?
194 # subpattern
195 # position of parser in subpattern
196 # retval (array)
197 parserStack = [[1, 1, False, pattern, 0, []]]
198
199 #try:
200 # sys._getframe(200)
201 # logger.error("Stack depth warning, pattern: %s", pattern)
202 # return
203 #except ValueError:
204 # pass
205
206 while True:
207 i = parserStack[-1][3][parserStack[-1][4]]
208 if i in "0123456789" and (size is None or parserStack[-1][3][parserStack[-1][4]-1] not in "lL"):
209 try:
210 size = size * 10 + int(i)
211 except TypeError:
212 size = int(i)
213 isArray = False
214 elif i in "Ll" and size is None:
215 size = self.decode_payload_varint()
216 if i == "L":
217 isArray = True
218 else:

Callers 7

decode_payload_nodeMethod · 0.95
bm_command_errorMethod · 0.95
bm_command_getdataMethod · 0.95
_command_invMethod · 0.95
bm_command_objectMethod · 0.95
_decode_addrMethod · 0.95
bm_command_versionMethod · 0.95

Calls 2

decode_payload_varintMethod · 0.95

Tested by

no test coverage detected