MCPcopy Index your code
hub / github.com/apache/dubbo-python2 / _encode_list

Method _encode_list

dubbo/codec/encoder.py:338–381  ·  view source on GitHub ↗

对一个列表进行编码 :param value: :return:

(self, value)

Source from the content-addressed store, hash-verified

336 return result
337
338 def _encode_list(self, value):
339 """
340 对一个列表进行编码
341 :param value:
342 :return:
343 """
344 result = []
345 length = len(value)
346 if length == 0:
347 # 没有值则无法判断类型,一律返回null
348 return self._encode_single_value(None)
349 if isinstance(value[0], bool):
350 _type = '[boolean'
351 elif isinstance(value[0], int):
352 _type = '[int'
353 elif isinstance(value[0], float):
354 _type = '[double'
355 elif isinstance(value[0], str):
356 _type = '[string'
357 elif isinstance(value[0], Object):
358 _type = '[object'
359 else:
360 raise HessianTypeError('Unknown list type: {}'.format(value[0]))
361 if length < 0x7:
362 result.append(0x70 + length)
363 if _type not in self.types:
364 self.types.append(_type)
365 result.extend(self._encode_single_value(_type))
366 else:
367 result.extend(self._encode_single_value(self.types.index(_type)))
368 else:
369 result.append(0x56)
370 if _type not in self.types:
371 self.types.append(_type)
372 result.extend(self._encode_single_value(_type))
373 else:
374 result.extend(self._encode_single_value(self.types.index(_type)))
375 result.extend(self._encode_single_value(length))
376 for v in value:
377 if type(value[0]) != type(v):
378 raise HessianTypeError('All elements in list must be the same type, first type'
379 ' is {0} but current type is {1}'.format(type(value[0]), type(v)))
380 result.extend(self._encode_single_value(v))
381 return result
382
383 def _encode_single_value(self, value):
384 """

Callers 1

_encode_single_valueMethod · 0.95

Calls 3

_encode_single_valueMethod · 0.95
HessianTypeErrorClass · 0.90
formatMethod · 0.80

Tested by

no test coverage detected