aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/argaze/DataStructures.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/argaze/DataStructures.py b/src/argaze/DataStructures.py
index 74fb8b0..e6dfc8b 100644
--- a/src/argaze/DataStructures.py
+++ b/src/argaze/DataStructures.py
@@ -8,6 +8,7 @@ __copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)"
__license__ = "BSD"
from typing import TypeVar, Tuple
+from dataclasses import asdict
import collections
import json
import ast
@@ -27,6 +28,16 @@ DataType = TypeVar('Data')
TimeStampedBufferType = TypeVar('TimeStampedBuffer', bound="TimeStampedBuffer")
# Type definition for type annotation convenience
+def as_dict(dataclass_object) -> dict:
+ """
+ Get dataclass object attributes values as a dictionary.
+
+ Returns:
+ values: dictionary of dataclass attributes values
+ """
+
+ return {key: vars(dataclass_object)[key] for key in asdict(dataclass_object).keys()}
+
class JsonEncoder(json.JSONEncoder):
"""Specific ArGaze JSON Encoder."""