mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
removed data formatter
This commit is contained in:
parent
857916285d
commit
f83751cc80
1 changed files with 0 additions and 24 deletions
|
@ -1,24 +0,0 @@
|
||||||
# File: arq_data_formatter.py
|
|
||||||
|
|
||||||
import json
|
|
||||||
|
|
||||||
class ARQDataFormatter:
|
|
||||||
def __init__(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def encapsulate(self, data, type_key="p2pmsg"):
|
|
||||||
"""Encapsulate data into the specified format with the given type key."""
|
|
||||||
formatted_data = {type_key: data}
|
|
||||||
return json.dumps(formatted_data)
|
|
||||||
|
|
||||||
def decapsulate(self, byte_data):
|
|
||||||
"""Decapsulate data from the specified format, returning both the data and the type."""
|
|
||||||
try:
|
|
||||||
json_data = byte_data.decode('utf-8') # Decode byte array to string
|
|
||||||
parsed_data = json.loads(json_data)
|
|
||||||
if parsed_data and isinstance(parsed_data, dict):
|
|
||||||
for key, value in parsed_data.items():
|
|
||||||
return key, value
|
|
||||||
return "raw", byte_data
|
|
||||||
except (json.JSONDecodeError, UnicodeDecodeError):
|
|
||||||
return "raw", byte_data
|
|
Loading…
Reference in a new issue