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

Method _encode_float

dubbo/codec/encoder.py:215–259  ·  view source on GitHub ↗

对浮点类型进行编码 :param value: :return:

(value)

Source from the content-addressed store, hash-verified

213
214 @staticmethod
215 def _encode_float(value):
216 """
217 对浮点类型进行编码
218 :param value:
219 :return:
220 """
221 result = []
222 int_value = int(value)
223 if int_value == value:
224 if int_value == 0:
225 result.append(0x5b)
226 return result
227 elif int_value == 1:
228 result.append(0x5c)
229 return result
230 elif -0x80 <= int_value < 0x80:
231 result.append(0x5d)
232 result.append(int_value)
233 return result
234 elif -0x8000 <= int_value < 0x8000:
235 result.append(0x5e)
236 result.append(int_value >> 8)
237 result.append(int_value)
238 return result
239
240 mills = int(value * 1000)
241 if 0.001 * mills == value and MIN_INT_32 <= mills <= MAX_INT_32:
242 result.append(0x5f)
243 result.append(mills >> 24)
244 result.append(mills >> 16)
245 result.append(mills >> 8)
246 result.append(mills)
247 return result
248
249 bits = double_to_long_bits(value)
250 result.append(ord('D'))
251 result.append(bits >> 56)
252 result.append(bits >> 48)
253 result.append(bits >> 40)
254 result.append(bits >> 32)
255 result.append(bits >> 24)
256 result.append(bits >> 16)
257 result.append(bits >> 8)
258 result.append(bits)
259 return result
260
261 @staticmethod
262 def _encode_utf(value):

Callers 1

_encode_single_valueMethod · 0.95

Calls 1

double_to_long_bitsFunction · 0.90

Tested by

no test coverage detected