mirror of
https://github.com/markqvist/LXMF.git
synced 2025-07-30 10:29:17 -04:00
Added utility functions
This commit is contained in:
parent
fc99010a3d
commit
537f1823b6
1 changed files with 42 additions and 1 deletions
41
LXMF/LXMF.py
41
LXMF/LXMF.py
|
@ -74,3 +74,44 @@ AM_OPUS_LOSSLESS = 0x19
|
||||||
# Custom, unspecified audio mode, the client must
|
# Custom, unspecified audio mode, the client must
|
||||||
# determine it itself based on the included data.
|
# determine it itself based on the included data.
|
||||||
AM_CUSTOM = 0xFF
|
AM_CUSTOM = 0xFF
|
||||||
|
|
||||||
|
|
||||||
|
##########################################################
|
||||||
|
# The following helper functions makes it easier to #
|
||||||
|
# handle and operate on LXMF data in client programs #
|
||||||
|
##########################################################
|
||||||
|
|
||||||
|
import RNS.vendor.umsgpack as msgpack
|
||||||
|
def display_name_from_app_data(app_data=None):
|
||||||
|
if app_data == None:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
# Version 0.5.0+ announce format
|
||||||
|
if (app_data[0] >= 0x90 and app_data[0] <= 0x9f) or app_data[0] == 0xdc:
|
||||||
|
peer_data = msgpack.unpackb(app_data)
|
||||||
|
if type(peer_data) == list:
|
||||||
|
if len(peer_data) < 1:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return peer_data[0].decode("utf-8")
|
||||||
|
|
||||||
|
# Original announce format
|
||||||
|
else:
|
||||||
|
return app_data.decode("utf-8")
|
||||||
|
|
||||||
|
def stamp_cost_from_app_data(app_data=None):
|
||||||
|
if app_data == None:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
# Version 0.5.0+ announce format
|
||||||
|
if (app_data[0] >= 0x90 and app_data[0] <= 0x9f) or app_data[0] == 0xdc:
|
||||||
|
peer_data = msgpack.unpackb(app_data)
|
||||||
|
if type(peer_data) == list:
|
||||||
|
if len(peer_data) < 2:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return peer_data[1]
|
||||||
|
|
||||||
|
# Original announce format
|
||||||
|
else:
|
||||||
|
return None
|
Loading…
Add table
Add a link
Reference in a new issue