mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
Don't distinguish between str and bytes when serializing
This makes it easier to use some requests like ReqPqRequest which needs a string of bytes, not a valid utf-8 string per se.
This commit is contained in:
parent
1518be0b95
commit
fb0898b9cb
|
@ -87,6 +87,9 @@ class TLObject:
|
|||
@staticmethod
|
||||
def serialize_bytes(data):
|
||||
"""Write bytes by using Telegram guidelines"""
|
||||
if isinstance(data, str):
|
||||
data = data.encode('utf-8')
|
||||
|
||||
r = []
|
||||
if len(data) < 254:
|
||||
padding = (len(data) + 1) % 4
|
||||
|
@ -112,10 +115,6 @@ class TLObject:
|
|||
r.append(bytes(padding))
|
||||
return b''.join(r)
|
||||
|
||||
@staticmethod
|
||||
def serialize_string(string):
|
||||
return TLObject.serialize_bytes(string.encode('utf-8'))
|
||||
|
||||
# These should be overrode
|
||||
def to_dict(self, recursive=True):
|
||||
return {}
|
||||
|
|
|
@ -493,7 +493,7 @@ class TLGenerator:
|
|||
builder.write("struct.pack('<d', {})".format(name))
|
||||
|
||||
elif 'string' == arg.type:
|
||||
builder.write('TLObject.serialize_string({})'.format(name))
|
||||
builder.write('TLObject.serialize_bytes({})'.format(name))
|
||||
|
||||
elif 'Bool' == arg.type:
|
||||
# 0x997275b5 if boolean else 0xbc799737
|
||||
|
|
Loading…
Reference in New Issue
Block a user