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 = IPDesc() proto.ParseFromString(serialized) desc = _ip_desc_from_proto(proto) return desc
def _ip_desc_to_proto(desc): """ Convert an IP descriptor to protobuf. Args: desc (magma.mobilityd.IPDesc): IP descriptor Returns: proto (protos.keyval_pb2.IPDesc): protobuf of :desc: """ ip = IPAddress( version=_ip_version_int_to_proto(desc.ip_block.version), address=desc.ip.packed, ) ip_block = IPBlock( version=_ip_version_int_to_proto(desc.ip_block.version), net_address=desc.ip_block.network_address.packed, prefix_len=desc.ip_block.prefixlen, ) state = _desc_state_str_to_proto(desc.state) sid = SubscriberID( id=desc.sid, type=SubscriberID.IMSI, ) proto = IPDesc(ip=ip, ip_block=ip_block, state=state, sid=sid) return proto