예제 #1
0
 def _deserialize_proto(serialized_rule):
     proto_wrapper = RedisState()
     proto_wrapper.ParseFromString(serialized_rule)
     serialized_proto = proto_wrapper.serialized_msg
     proto = proto_class()
     proto.ParseFromString(serialized_proto)
     return proto
예제 #2
0
파일: containers.py 프로젝트: alexsn/magma
    def _get_version(self, key):
        value = self.redis.get(key)
        if value is None:
            return 0

        proto_wrapper = RedisState()
        proto_wrapper.ParseFromString(value)
        return proto_wrapper.version
예제 #3
0
    def is_garbage(self, key: str) -> bool:
        """Return if d[key:type] has been marked 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)
        return proto_wrapper.is_garbage
예제 #4
0
    def get_version(self, key: str) -> int:
        """Return the version of the value for key *key:type*. Returns 0 if
        key is not in the map
        """
        composite_key = self._make_composite_key(key)
        value = self.redis.get(composite_key)
        if value is None:
            return 0

        proto_wrapper = RedisState()
        proto_wrapper.ParseFromString(value)
        return proto_wrapper.version
예제 #5
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)
예제 #6
0
    def get_version(self, key):
        """Return the version of the value for key *key*. Returns 0 if
        key is not in the map
        """
        try:
            value = self.cache[key]
        except KeyError:
            pickled_key = self._pickle_key(key)
            value = self.redis.hget(self.key, pickled_key)
            if value is None:
                return 0

        proto_wrapper = RedisState()
        proto_wrapper.ParseFromString(value)
        return proto_wrapper.version
예제 #7
0
def deserialize_ip_desc(serialized):
    """
    Deserialize protobuf string to an IP descriptor.

    Args:
        serialized (bytes): object to deserialize
    Returns:
        block (magma.mobilityd.IPDesc): deserialized object
    """
    proto_wrapper = RedisState()
    proto_wrapper.ParseFromString(serialized)
    serialized_proto = proto_wrapper.serialized_msg
    proto = IPDesc()
    proto.ParseFromString(serialized_proto)
    desc = _ip_desc_from_proto(proto)
    return desc
예제 #8
0
    def __getitem__(self, key: str) -> T:
        """Return the item of dictionary with key *key:type*. Raises a
        :exc:`KeyError` if *key:type* is not in the map or the object is
        garbage
        """
        if ':' in key:
            raise ValueError("Key %s cannot contain ':' char" % key)
        composite_key = self._make_composite_key(key)
        serialized_value = self.redis.get(composite_key)
        if serialized_value is None:
            raise KeyError(composite_key)

        proto_wrapper = RedisState()
        proto_wrapper.ParseFromString(serialized_value)
        if proto_wrapper.is_garbage:
            raise KeyError("Key %s is garbage" % key)

        return self.serde.deserialize(serialized_value)
예제 #9
0
def deserialize_ip_descs(serialized):
    """
    Deserialize protobuf string to a list of IP descriptors.

    Args:
        serialized (bytes): object to deserialize
    Returns:
        block ([magma.mobilityd.IPDesc]): deserialized object
    """
    proto_wrapper = RedisState()
    proto_wrapper.ParseFromString(serialized)
    serialized_proto = proto_wrapper.serialized_msg
    proto = IPDescs()
    proto.ParseFromString(serialized_proto)
    descs = [
        _ip_desc_from_proto(desc_proto)
        for desc_proto in proto.ip_descs]
    return descs
예제 #10
0
 def _deserialize_json(serialized_rule):
     proto_wrapper = RedisState()
     proto_wrapper.ParseFromString(serialized_rule)
     serialized_msg = proto_wrapper.serialized_msg
     msg = json.loads(serialized_msg.decode('utf-8'))
     return msg
예제 #11
0
 def _deserialize_version(serialized_rule: str) -> T:
     proto_wrapper = RedisState()
     proto_wrapper.ParseFromString(serialized_rule)
     return proto_wrapper.version
예제 #12
0
 def _deserialize_json(serialized_rule: str) -> T:
     proto_wrapper = RedisState()
     proto_wrapper.ParseFromString(serialized_rule)
     serialized_msg = proto_wrapper.serialized_msg
     msg = jsonpickle.decode(serialized_msg.decode('utf-8'))
     return msg