语言:python
问题:通过 socket 收到 b'\x7d\x76\x76\x76\x76\x76\x76\x76\x[XOR]\x7d'
我该如何去处理这串 bytes。
1 )在 recv 中找到 0x7e 2 )校验 3 )进一步处理
python 不像 c 那么好处理字节流。 求大神赐教
语言:python
问题:通过 socket 收到 b'\x7d\x76\x76\x76\x76\x76\x76\x76\x[XOR]\x7d'
我该如何去处理这串 bytes。
1 )在 recv 中找到 0x7e 2 )校验 3 )进一步处理
python 不像 c 那么好处理字节流。 求大神赐教
|
1
c 语言可以用 byte*。但 python 我想不出怎么处理
|
|
pepesiiSep 10, 2017
2
|
|
estSep 10, 2017
3
> python 不像 c 那么好处理字节流。
那就用 C 啊。 |
|
junzkiSep 11, 2017
4
C 语言怎么写,Python 也用相同的写法。拿 Python 的 byte 当 C 语言的 char* 用就好了。
|
|
NoAnyLoveSep 11, 2017
5
没看懂你要做什么,排版看得头疼。。。。。如果收到的数据有固定的结构或者头部,用 struct 根据 field 来拆。如果没有固定的格式,依赖特殊的 magic number,那么无论是 bytes 还是 bytearray 都是可以 find 或者 index 的。
一句话来说,用 Python 处理数据绝对比用 C 简单啊 |
|
BBCCBBSep 11, 2017
7
python3 调用`bytes`的`decode()`方法可以转成`str`,`str`调用`encode()`方法可以转成`bytes`, 问的是这个??
|
|
BBCCBBSep 11, 2017
8
而且 python 的 bytes 类型也有 find 这种方法
|
|
9
struct + memoryview
|