Example #1
0
    def serialize(cls, enr: ENRAPI) -> Tuple[bytes, ...]:
        serialized_sequence_number = big_endian_int.serialize(
            enr.sequence_number)

        sorted_key_value_pairs = sorted(enr.items(),
                                        key=operator.itemgetter(0))

        serialized_keys = tuple(
            binary.serialize(key) for key, _ in sorted_key_value_pairs)
        values_and_serializers = tuple(
            (value, ENR_KEY_SEDES_MAPPING.get(key, FALLBACK_ENR_VALUE_SEDES))
            for key, value in sorted_key_value_pairs)
        serialized_values = tuple(
            value_serializer.serialize(value)
            for value, value_serializer in values_and_serializers)
        return tuple(
            cons(
                serialized_sequence_number,
                interleave((serialized_keys, serialized_values)),
            ))
 def serialize(cls, enr: "ENR") -> Tuple[bytes, ...]:
     serialized_signature = binary.serialize(enr.signature)
     serialized_content = ENRContentSedes.serialize(enr)
     return (serialized_signature, ) + serialized_content