Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
fastjson
Browse files Browse the repository at this point in the history
  • Loading branch information
ralwing committed Oct 30, 2024
1 parent 29e9030 commit 5aabcd3
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from geometry_msgs.msg import Pose
from geometry_msgs.msg import Quaternion as RosQuaternion
from geometry_msgs.msg import Vector3
import jsonschema
import fastjsonschema
import numpy as np
from perception_eval.common import ObjectType
from perception_eval.common.object import DynamicObject
Expand Down Expand Up @@ -305,27 +305,26 @@ def fill_xyzw_quat(q: Quaternion | None) -> dict:
# utils for writing each perception frame result to a file
class FrameDescriptionWriter:
schema: dict = None
validate_func = None

@classmethod
def load_schema(cls) -> None:
if cls.schema is None:
if cls.schema is None or cls.validate_func is None:
package_share_directory = get_package_share_directory("driving_log_replayer")
schema_file_path = (
Path(package_share_directory) / "config" / "object_output_schema.json"
)
with schema_file_path.open() as file:
cls.schema = json.load(file)
# Compile the schema into a validator instance
validator_cls = jsonschema.validators.validator_for(cls.schema)
validator_cls.check_schema(cls.schema)
cls.validator = validator_cls(cls.schema)
# Compile the schema into a validation function
cls.validate_func = fastjsonschema.compile(cls.schema)

@classmethod
def is_object_structure_valid(cls, objdata: dict | None) -> bool:
cls.load_schema()
try:
cls.validator.validate(objdata)
except jsonschema.exceptions.ValidationError:
cls.validate_func(objdata)
except fastjsonschema.exceptions.JsonSchemaException:
return False
else:
return True
Expand Down

0 comments on commit 5aabcd3

Please sign in to comment.