def decode(cls, kwargs_protobuf_object: Any) -> "Kwargs": """ Decode a protocol buffer object that corresponds with this class into an instance of this class. A new instance of this class is created that matches the protocol buffer object in the 'kwargs_protobuf_object' argument. :param kwargs_protobuf_object: the protocol buffer object whose type corresponds with this class. :return: A new instance of this class that matches the protocol buffer object in the 'kwargs_protobuf_object' argument. """ kwargs = DictProtobufStructSerializer.decode(kwargs_protobuf_object.kwargs) return cls(kwargs)
def encode(kwargs_protobuf_object: Any, kwargs_object: "Kwargs") -> None: """ Encode an instance of this class into the protocol buffer object. The protocol buffer object in the kwargs_protobuf_object argument is matched with the instance of this class in the 'kwargs_object' argument. :param kwargs_protobuf_object: the protocol buffer object whose type corresponds with this class. :param kwargs_object: an instance of this class to be encoded in the protocol buffer object. :return: None """ kwargs_protobuf_object.kwargs = DictProtobufStructSerializer.encode( kwargs_object.body)
def decode(cls, state_protobuf_object) -> "State": """ Decode a protocol buffer object that corresponds with this class into an instance of this class. A new instance of this class must be created that matches the protocol buffer object in the 'state_protobuf_object' argument. :param state_protobuf_object: the protocol buffer object whose type corresponds with this class. :return: A new instance of this class that matches the protocol buffer object in the 'state_protobuf_object' argument. """ state_dict = DictProtobufStructSerializer.decode( state_protobuf_object.state) return cls(state_dict["ledger_id"], state_dict["body"])
def decode(cls, agents_info_protobuf_object: Any) -> "AgentsInfo": """ Decode a protocol buffer object that corresponds with this class into an instance of this class. A new instance of this class is created that matches the protocol buffer object in the 'agents_info_protobuf_object' argument. :param agents_info_protobuf_object: the protocol buffer object whose type corresponds with this class. :return: A new instance of this class that matches the protocol buffer object in the 'agents_info_protobuf_object' argument. """ body = DictProtobufStructSerializer.decode( agents_info_protobuf_object.agents_info) return cls(body)
def decode(cls, raw_transaction_protobuf_object) -> "RawTransaction": """ Decode a protocol buffer object that corresponds with this class into an instance of this class. A new instance of this class must be created that matches the protocol buffer object in the 'raw_transaction_protobuf_object' argument. :param raw_transaction_protobuf_object: the protocol buffer object whose type corresponds with this class. :return: A new instance of this class that matches the protocol buffer object in the 'raw_transaction_protobuf_object' argument. """ raw_transaction_dict = DictProtobufStructSerializer.decode( raw_transaction_protobuf_object.raw_transaction) return cls(raw_transaction_dict["ledger_id"], raw_transaction_dict["body"])
def encode(agents_info_protobuf_object: Any, agents_info_object: "AgentsInfo") -> None: """ Encode an instance of this class into the protocol buffer object. The protocol buffer object in the agents_info_protobuf_object argument is matched with the instance of this class in the 'agents_info_object' argument. :param agents_info_protobuf_object: the protocol buffer object whose type corresponds with this class. :param agents_info_object: an instance of this class to be encoded in the protocol buffer object. :return: None """ agents_info_protobuf_object.agents_info = DictProtobufStructSerializer.encode( agents_info_object.body)
def test_encode_decode_ii(): """Test encode decode logic.""" case = { "key1": True, "key2": 0.12, "key3": 100, "key4": "some string", "key5": b"some bytes string", "key6": {"key1": True, "key2": 0.12}, } encoded = DictProtobufStructSerializer.encode(case) assert isinstance(encoded, bytes) decoded = DictProtobufStructSerializer.decode(encoded) assert case == decoded
def decode(cls, transaction_digest_protobuf_object: Any) -> "TransactionDigest": """ Decode a protocol buffer object that corresponds with this class into an instance of this class. A new instance of this class must be created that matches the protocol buffer object in the 'transaction_digest_protobuf_object' argument. :param transaction_digest_protobuf_object: the protocol buffer object whose type corresponds with this class. :return: A new instance of this class that matches the protocol buffer object in the 'transaction_digest_protobuf_object' argument. """ transaction_digest_dict = DictProtobufStructSerializer.decode( transaction_digest_protobuf_object.transaction_digest) return cls(transaction_digest_dict["ledger_id"], transaction_digest_dict["body"])
def decode(cls, signed_message_protobuf_object: Any) -> "SignedMessage": """ Decode a protocol buffer object that corresponds with this class into an instance of this class. A new instance of this class must be created that matches the protocol buffer object in the 'signed_message_protobuf_object' argument. :param signed_message_protobuf_object: the protocol buffer object whose type corresponds with this class. :return: A new instance of this class that matches the protocol buffer object in the 'signed_message_protobuf_object' argument. """ signed_message_dict = DictProtobufStructSerializer.decode( signed_message_protobuf_object.signed_message) return cls( signed_message_dict["ledger_id"], signed_message_dict["body"], signed_message_dict["is_deprecated_mode"], )
def encode(state_protobuf_object, state_object: "State") -> None: """ Encode an instance of this class into the protocol buffer object. The protocol buffer object in the state_protobuf_object argument must be matched with the instance of this class in the 'state_object' argument. :param state_protobuf_object: the protocol buffer object whose type corresponds with this class. :param state_object: an instance of this class to be encoded in the protocol buffer object. :return: None """ state_dict = { "ledger_id": state_object.ledger_id, "body": state_object.body, } state_protobuf_object.state = DictProtobufStructSerializer.encode( state_dict)
def encode(raw_transaction_protobuf_object, raw_transaction_object: "RawTransaction") -> None: """ Encode an instance of this class into the protocol buffer object. The protocol buffer object in the raw_transaction_protobuf_object argument must be matched with the instance of this class in the 'raw_transaction_object' argument. :param raw_transaction_protobuf_object: the protocol buffer object whose type corresponds with this class. :param raw_transaction_object: an instance of this class to be encoded in the protocol buffer object. :return: None """ raw_transaction_dict = { "ledger_id": raw_transaction_object.ledger_id, "body": raw_transaction_object.body, } raw_transaction_protobuf_object.raw_transaction = DictProtobufStructSerializer.encode( raw_transaction_dict)
def encode(signed_message_protobuf_object, signed_message_object: "SignedMessage") -> None: """ Encode an instance of this class into the protocol buffer object. The protocol buffer object in the signed_message_protobuf_object argument must be matched with the instance of this class in the 'signed_message_object' argument. :param signed_message_protobuf_object: the protocol buffer object whose type corresponds with this class. :param signed_message_object: an instance of this class to be encoded in the protocol buffer object. :return: None """ signed_message_dict = { "ledger_id": signed_message_object.ledger_id, "body": signed_message_object.body, "is_deprecated_mode": signed_message_object.is_deprecated_mode, } signed_message_protobuf_object.signed_message = DictProtobufStructSerializer.encode( signed_message_dict)
def encode( transaction_digest_protobuf_object, transaction_digest_object: "TransactionDigest", ) -> None: """ Encode an instance of this class into the protocol buffer object. The protocol buffer object in the transaction_digest_protobuf_object argument must be matched with the instance of this class in the 'transaction_digest_object' argument. :param transaction_digest_protobuf_object: the protocol buffer object whose type corresponds with this class. :param transaction_digest_object: an instance of this class to be encoded in the protocol buffer object. :return: None """ transaction_digest_dict = { "ledger_id": transaction_digest_object.ledger_id, "body": transaction_digest_object.body, } transaction_digest_protobuf_object.transaction_digest = DictProtobufStructSerializer.encode( transaction_digest_dict)
def encode( signed_transaction_protobuf_object: Any, signed_transaction_object: "SignedTransaction", ) -> None: """ Encode an instance of this class into the protocol buffer object. The protocol buffer object in the signed_transaction_protobuf_object argument must be matched with the instance of this class in the 'signed_transaction_object' argument. :param signed_transaction_protobuf_object: the protocol buffer object whose type corresponds with this class. :param signed_transaction_object: an instance of this class to be encoded in the protocol buffer object. :return: None """ signed_transaction_dict = { "ledger_id": signed_transaction_object.ledger_id, "body": signed_transaction_object.body, } signed_transaction_protobuf_object.signed_transaction = DictProtobufStructSerializer.encode( signed_transaction_dict)
def decode(cls, terms_protobuf_object) -> "Terms": """ Decode a protocol buffer object that corresponds with this class into an instance of this class. A new instance of this class must be created that matches the protocol buffer object in the 'terms_protobuf_object' argument. :param terms_protobuf_object: the protocol buffer object whose type corresponds with this class. :return: A new instance of this class that matches the protocol buffer object in the 'terms_protobuf_object' argument. """ terms_dict = DictProtobufStructSerializer.decode( terms_protobuf_object.terms) return cls( terms_dict["ledger_id"], terms_dict["sender_address"], terms_dict["counterparty_address"], terms_dict["amount_by_currency_id"], terms_dict["quantities_by_good_id"], terms_dict["nonce"], terms_dict["is_sender_payable_tx_fee"], dict(terms_dict["fee_by_currency_id"]), terms_dict["is_strict"], **dict(terms_dict["kwargs"]), )
def encode(terms_protobuf_object, terms_object: "Terms") -> None: """ Encode an instance of this class into the protocol buffer object. The protocol buffer object in the terms_protobuf_object argument must be matched with the instance of this class in the 'terms_object' argument. :param terms_protobuf_object: the protocol buffer object whose type corresponds with this class. :param terms_object: an instance of this class to be encoded in the protocol buffer object. :return: None """ terms_dict = { "ledger_id": terms_object.ledger_id, "sender_address": terms_object.sender_address, "counterparty_address": terms_object.counterparty_address, "amount_by_currency_id": terms_object.amount_by_currency_id, "quantities_by_good_id": terms_object.quantities_by_good_id, "nonce": terms_object.nonce, "is_sender_payable_tx_fee": terms_object.is_sender_payable_tx_fee, "fee_by_currency_id": terms_object.fee_by_currency_id, "is_strict": terms_object.is_strict, "kwargs": terms_object.kwargs, } terms_protobuf_object.terms = DictProtobufStructSerializer.encode( terms_dict)