X-Git-Url: https://code.kerkeslager.com/?p=ton;a=blobdiff_plain;f=don%2Ftags.py;h=db54dfe8878941a4386b84942c4a299d6d9ef196;hp=06244a484515e9b58df902688ef9bc7f6ac654e7;hb=e5e265e2b155f2cf6766cb20b9588326d6114665;hpb=d868dec6061aee9949bcf83fd698a4cd5f30168f diff --git a/don/tags.py b/don/tags.py index 06244a4..db54dfe 100644 --- a/don/tags.py +++ b/don/tags.py @@ -8,8 +8,9 @@ INT8 = 0x10 INT16 = 0x11 INT32 = 0x12 INT64 = 0x13 -FLOAT = 0x20 -DOUBLE = 0x21 +# These are to be supported in the future +# FLOAT = 0x20 +# DOUBLE = 0x21 BINARY = 0x30 UTF8 = 0x31 UTF16 = 0x32 @@ -17,15 +18,15 @@ UTF32 = 0x33 LIST = 0x40 DICTIONARY = 0x41 +STRING_TAGS = set([UTF8, UTF16, UTF32]) + DEFAULT_INTEGER_ENCODING = INT32 -DEFAULT_DECIMAL_ENCODING = DOUBLE DEFAULT_STRING_ENCODING = UTF8 TaggedObject = collections.namedtuple('TaggedObject', ['tag', 'value']) _TYPES_TO_TAGS = { int: DEFAULT_INTEGER_ENCODING, - float: DEFAULT_DECIMAL_ENCODING, bytes: BINARY, str: DEFAULT_STRING_ENCODING, list: LIST, @@ -96,13 +97,13 @@ def autotag(o, **kwargs): raise TooWideError("Integer {} is too wide to be serialized") - if isinstance(o, float): - raise Exception('Unsupported type {}'.format(type(o))) - if isinstance(o, str): # TODO Support SMALLEST for preferred string tag return TaggedObject(tag = preferred_string_tag, value = o) + if isinstance(o, bytes): + return TaggedObject(tag = BINARY, value = o) + if isinstance(o, list): return TaggedObject( tag = LIST,