def serialize_state(state, length_label_size=STATE_LEN_2BYTES, schema=None): buff = [] for key, val in state.items(): if schema: buff.append(serialize_with_schema(state, key, schema)) else: buff.append(serialize(val)) state_data = b''.join(buff) state_len = encode_state_len(len(state_data), length_label_size) return state_data + utils.get_push_item(state_len)
def serialize_bytes(val): return utils.get_push_item(val)
def serialize_hex(val): res = bytes.fromhex(val) return utils.get_push_item(res)
def serialize_string(val): if val == '': res = pack_byte(0) res = str.encode(val, 'utf-8') return utils.get_push_item(res)
def hex(self): return utils.get_push_item(self.value).hex()