Пример #1
0
 def _serialize_json(msg: T, version: int) -> str:
     serialized_msg = jsonpickle.encode(msg)
     redis_state = RedisState(
         serialized_msg=serialized_msg.encode('utf-8'),
         version=version,
         is_garbage=False,
     )
     return redis_state.SerializeToString()
Пример #2
0
 def _serialize_proto(proto: T, version: int) -> str:
     serialized_proto = proto.SerializeToString()
     redis_state = RedisState(
         serialized_msg=serialized_proto,
         version=version,
         is_garbage=False,
     )
     return redis_state.SerializeToString()
Пример #3
0
def serialize_ip_desc(desc, version):
    """
    Serialize an IP descriptor to protobuf string.

    Args:
        desc (magma.mobilityd.IPDesc): object to serialize
    Returns:
        serialized (bytes): serialized object
    """
    proto = _ip_desc_to_proto(desc)
    serialized = proto.SerializeToString()
    redis_state = RedisState(serialized_msg=serialized, version=version)
    return redis_state.SerializeToString()
Пример #4
0
    def mark_as_garbage(self, key: str) -> Any:
        """Mark ``d[key:type]`` for garbage collection
        Raises a KeyError if *key:type* is not in the map.
        """
        composite_key = self._make_composite_key(key)
        value = self.redis.get(composite_key)
        if value is None:
            raise KeyError(composite_key)

        proto_wrapper = RedisState()
        proto_wrapper.ParseFromString(value)
        proto_wrapper.is_garbage = True
        garbage_serialized = proto_wrapper.SerializeToString()
        return self.redis.set(composite_key, garbage_serialized)
Пример #5
0
def serialize_ip_descs(descs, version):
    """
    Serialize a list of IP descriptor to protobuf string.

    Args:
        descs ([magma.mobilityd.IPDesc]): object to serialize
    Returns:
        serialized (bytes): serialized object
    """
    proto = IPDescs()
    desc_protos = [_ip_desc_to_proto(desc) for desc in descs]
    proto.ip_descs.extend(desc_protos)
    serialized = proto.SerializeToString()
    redis_state = RedisState(
        serialized_msg=serialized,
        version=version)
    return redis_state.SerializeToString()
Пример #6
0
 def _serialize_json(msg, version):
     serialized_msg = json.dumps(msg)
     redis_state = RedisState(serialized_msg=serialized_msg.encode('utf-8'),
                              version=version)
     return redis_state.SerializeToString()
Пример #7
0
 def _serialize_proto(proto, version):
     serialized_proto = proto.SerializeToString()
     redis_state = RedisState(serialized_msg=serialized_proto,
                              version=version)
     return redis_state.SerializeToString()