mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-06-11 19:56:53 +00:00
lpp json : let caller tell how to serialize
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from cayennelpp import LppFrame, LppData
|
||||
from cayennelpp.lpp_type import LppType
|
||||
|
||||
# type name "how to display vale"
|
||||
# Format : type name "how to display value"
|
||||
# display : None: (use lib default), []: only one value to display, ["field1", "field2" ...]: meaning of each field
|
||||
my_lpp_types = {
|
||||
0: ('digital input', []),
|
||||
@@ -33,7 +33,7 @@ my_lpp_types = {
|
||||
142: ('switch', []),
|
||||
}
|
||||
|
||||
def lpp_json_encoder (obj) :
|
||||
def lpp_json_encoder (obj, types = my_lpp_types) :
|
||||
"""Encode LppType, LppData, and LppFrame to JSON."""
|
||||
if isinstance(obj, LppFrame):
|
||||
return obj.data
|
||||
@@ -53,4 +53,4 @@ def lpp_json_encoder (obj) :
|
||||
i = i + 1
|
||||
d["value"] = val_dict
|
||||
return d
|
||||
raise TypeError(repr(obj) + " is not JSON serialized")
|
||||
raise TypeError(repr(obj) + " is not JSON serialized")
|
||||
|
||||
Reference in New Issue
Block a user