mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-04-20 22:13:49 +00:00
lpp json : let caller tell how to serialize
This commit is contained in:
parent
aa43afc3e7
commit
ad87eac280
1 changed files with 3 additions and 3 deletions
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue