def write_varint(value: types.uint, io: IO): """ Write unsigned `VarInt` to a file-like object. """ while value > 0x7F: io.write(bytes((value & 0x7F | 0x80, ))) value >>= 7 io.write(bytes((value, )))
def read_varint(io: IO) -> types.uint: """ Read unsigned `VarInt` from a file-like object. """ value = 0 for shift in count(0, 7): byte, = io.read(1) value |= (byte & 0x7F) << shift if not byte & 0x80: return value
def dump(self, value: Any, io: IO): unsigned_varint_serializer.dump(len(value), io) io.write(value)
def skip_bytes(io: IO): io.read(unsigned_varint_serializer.load(io))
def skip_fixed_64(io: IO): io.read(8)
def skip_fixed_32(io: IO): io.read(4)
def skip_varint(io: IO): while io.read(1)[0] & 0x80: pass
def load(self, io: IO) -> Any: return unpack('<d', io.read(8))[0]
def dump(self, value: Any, io: IO): io.write(pack('<d', value))
def load(self, io: IO) -> Any: return unpack('<f', io.read(4))[0]
def dump(self, value: Any, io: IO): io.write(b'\x01' if value else b'\x00')
def load(self, io: IO) -> Any: length = unsigned_varint_serializer.load(io) return io.read(length)