MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / varint

Function varint

examples/Protobuf Example/sensor_simulator.py:54–64  ·  view source on GitHub ↗

Encode an unsigned integer as a protobuf varint.

(n: int)

Source from the content-addressed store, hash-verified

52
53
54def varint(n: int) -> bytes:
55 """Encode an unsigned integer as a protobuf varint."""
56 out = bytearray()
57 while True:
58 b = n & 0x7F
59 n >>= 7
60 if n:
61 out.append(b | 0x80)
62 else:
63 out.append(b)
64 return bytes(out)
65
66
67def tag(field: int, wire: int) -> bytes:

Callers 4

tagFunction · 0.85
field_uintFunction · 0.85
field_stringFunction · 0.85
field_submsgFunction · 0.85

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected