def load_uvarint32(data: bytes) -> int: # use known uint32 field in an all-optional message buffer = bytearray(len(data) + 1) buffer[1:] = data buffer[0] = (1 << 3) | 0 # field number 1, wire type 0 msg = protobuf.decode(buffer, WebAuthnCredential, False) return msg.index
def load_uvarint64(data: bytes) -> int: # use known uint64 field in an all-optional message buffer = bytearray(len(data) + 1) buffer[1:] = data buffer[0] = (2 << 3) | 0 # field number 1, wire type 0 msg = protobuf.decode(buffer, EosAsset, False) return msg.symbol
def _wrap_protobuf_load( buffer: bytes, expected_type: type[LoadedMessageType], ) -> LoadedMessageType: try: return protobuf.decode(buffer, expected_type, experimental_enabled) except Exception as e: if __debug__: log.exception(__name__, e) if e.args: raise DataError("Failed to decode message: {}".format(e.args[0])) else: raise DataError("Failed to decode message")
def _wrap_protobuf_load( buffer: bytes, expected_type: type[LoadedMessageType], ) -> LoadedMessageType: try: msg = protobuf.decode(buffer, expected_type, experimental_enabled) if __debug__ and utils.EMULATOR: log.debug( __name__, "received message contents:\n%s", utils.dump_protobuf(msg) ) return msg except Exception as e: if __debug__: log.exception(__name__, e) if e.args: raise DataError("Failed to decode message: " + " ".join(e.args)) else: raise DataError("Failed to decode message")
def load_message(msg_type: Type[protobuf.MessageType], buffer: bytes) -> protobuf.MessageType: return protobuf.decode(buffer, msg_type, False)