async def write(self, msg: protobuf.MessageType, field_cache: protobuf.FieldCache = None) -> None: if __debug__: log.debug(__name__, "%s:%x write: %s", self.iface.iface_num(), self.sid, msg) if field_cache is None: field_cache = self._field_cache # write the message msg_size = protobuf.count_message(msg, field_cache) # prepare buffer if msg_size <= len(self.buffer_writer.buffer): # reuse preallocated buffer_writer = self.buffer_writer else: # message is too big, we need to allocate a new buffer buffer_writer = utils.BufferWriter(bytearray(msg_size)) buffer_writer.seek(0) protobuf.dump_message(buffer_writer, msg, field_cache) await codec_v1.write_message( self.iface, msg.MESSAGE_WIRE_TYPE, memoryview(buffer_writer.buffer)[:msg_size], ) # make sure we don't keep around fields of all protobuf types ever self._field_cache.clear()
def __init__(self, iface: WireInterface, sid: int) -> None: self.iface = iface self.sid = sid self.buffer = bytearray(PROTOBUF_BUFFER_SIZE) self.buffer_reader = utils.BufferReader(self.buffer) self.buffer_writer = utils.BufferWriter(self.buffer) self._field_cache = {} # type: protobuf.FieldCache
def __init__(self, iface: WireInterface, sid: int, buffer: bytearray) -> None: self.iface = iface self.sid = sid self.buffer = buffer self.buffer_writer = utils.BufferWriter(self.buffer) self._field_cache: protobuf.FieldCache = {}
def set(auth_message: protobuf.MessageType) -> None: buffer = bytearray(protobuf.count_message(auth_message)) writer = utils.BufferWriter(buffer) protobuf.dump_message(writer, auth_message) storage.cache.set( storage.cache.APP_COMMON_AUTHORIZATION_TYPE, auth_message.MESSAGE_WIRE_TYPE.to_bytes(2, "big"), ) storage.cache.set(storage.cache.APP_COMMON_AUTHORIZATION_DATA, buffer)