Closed diqiu114 closed 1 year ago
改下decode函数,return data.decode('utf-8')
哇,可以了,好牛逼,太神奇了 冒昧的问下,这两个函数是干什么的,以及怎么用? def decode(data): return data
def encode(data): return data
就是把收到的数据通过这段代码解码,return
回去的就是最终显示的内容,参数传进来的就是收到的字节数据。
代码是python
语法,参数是bytes
类型,我这里就是将bytes
类型的字节数据转换为str
类型的字符串,用了bytes_data.decode("utf-8")
函数,utf-8
是字符编码,也就是说你甚至可以发送emoji表情什么的🍊 🍇 😀 😅 😇,你也可以在函数里面进行其它操作,只要符合python
语法就可以, 比如在后面加上一串字符串return data.decode("utf-8") + "\n==== hello ====="
想要协议接受数据中含有回车换行符时,在接受数据界面中直接显示为换行(不显示转义字符),但在发送时允许含有转义字符(因为在协议插件里,发送时无法直接以按Enter表示回车换行符)