MCPcopy Create free account
hub / github.com/MaaXYZ/MaaFramework / StringBuffer

Class StringBuffer

source/binding/Python/maa/buffer.py:11–115  ·  view source on GitHub ↗

字符串缓冲区 / String buffer 用于在 Python 和 C API 之间传递字符串数据。 Used to pass string data between Python and C API.

Source from the content-addressed store, hash-verified

9
10
11class StringBuffer:
12 """字符串缓冲区 / String buffer
13
14 用于在 Python 和 C API 之间传递字符串数据。
15 Used to pass string data between Python and C API.
16 """
17
18 _handle: MaaStringBufferHandle
19 _own: bool
20
21 def __init__(self, handle: Optional[MaaStringBufferHandle] = None):
22 self._set_api_properties()
23
24 if handle:
25 self._handle = handle
26 self._own = False
27 else:
28 self._handle = Library.framework().MaaStringBufferCreate()
29 self._own = True
30
31 if not self._handle:
32 raise RuntimeError("Failed to create string buffer.")
33
34 def __del__(self):
35 if self._handle and self._own:
36 Library.framework().MaaStringBufferDestroy(self._handle)
37
38 def get(self) -> str:
39 """获取缓冲区内容 / Get buffer content
40
41 Returns:
42 str: 字符串内容 / String content
43 """
44 buff = Library.framework().MaaStringBufferGet(self._handle)
45 sz = Library.framework().MaaStringBufferSize(self._handle)
46 return ctypes.string_at(buff, sz).decode()
47
48 def set(self, value: Union[str, bytes]) -> bool:
49 """设置缓冲区内容 / Set buffer content
50
51 Args:
52 value: 字符串或字节数据 / String or bytes data
53
54 Returns:
55 bool: 是否成功 / Whether successful
56 """
57 if isinstance(value, str):
58 value = value.encode()
59 return bool(Library.framework().MaaStringBufferSetEx(self._handle, value, len(value)))
60
61 @property
62 def empty(self) -> bool:
63 """判断缓冲区是否为空 / Check if buffer is empty
64
65 Returns:
66 bool: 是否为空 / Whether empty
67 """
68 return bool(Library.framework().MaaStringBufferIsEmpty(self._handle))

Callers 15

get_node_dataMethod · 0.70
get_anchorMethod · 0.70
get_node_dataMethod · 0.70
hashMethod · 0.70
get_action_detailMethod · 0.70
get_node_detailMethod · 0.70
get_task_detailMethod · 0.70
shell_outputMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected