相关疑难解决方法(0)

如何从原始(二进制)ctype缓冲区构建python字符串?

我正在玩Python和ctypes,我无法弄清楚如何解决这个问题.我调用一个填充原始二进制数据的C函数.我的代码看起来像这样:

class Client():
  def __init__(self):
    self.__BUFSIZE = 1024*1024
    self.__buf = ctypes.create_string_buffer(self.__BUFSIZE)
    self.client = ctypes.cdll.LoadLibrary(r"I:\bin\client.dll")


  def do_something(self):
    len_written = self.client.fill_raw_buffer(self.__buf, self.__BUFSIZE)
    my_string = repr(self.__buf.value)
    print my_string
Run Code Online (Sandbox Code Playgroud)

问题是我正在接收二进制数据(带有0x00),当我尝试构建my_string时它被截断了.如果self._buf包含空字节0x00,我如何构建my_string?

欢迎任何想法.谢谢

python string ctypes

2
推荐指数
1
解决办法
3937
查看次数

标签 统计

ctypes ×1

python ×1

string ×1