obstruct 0.4.0__tar.gz → 0.5.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. {obstruct-0.4.0 → obstruct-0.5.1}/.idea/workspace.xml +48 -7
  2. {obstruct-0.4.0 → obstruct-0.5.1}/PKG-INFO +5 -3
  3. {obstruct-0.4.0 → obstruct-0.5.1}/README.md +4 -2
  4. obstruct-0.5.1/src/obstruct/__version__.py +1 -0
  5. {obstruct-0.4.0 → obstruct-0.5.1}/src/obstruct/aot/unpack.py +6 -6
  6. {obstruct-0.4.0 → obstruct-0.5.1}/src/obstruct/struct_type.py +3 -23
  7. {obstruct-0.4.0 → obstruct-0.5.1}/test/test_speed.py +2 -2
  8. obstruct-0.4.0/src/obstruct/__version__.py +0 -1
  9. {obstruct-0.4.0 → obstruct-0.5.1}/.idea/.gitignore +0 -0
  10. {obstruct-0.4.0 → obstruct-0.5.1}/.idea/inspectionProfiles/Project_Default.xml +0 -0
  11. {obstruct-0.4.0 → obstruct-0.5.1}/.idea/inspectionProfiles/profiles_settings.xml +0 -0
  12. {obstruct-0.4.0 → obstruct-0.5.1}/.idea/misc.xml +0 -0
  13. {obstruct-0.4.0 → obstruct-0.5.1}/.idea/modules.xml +0 -0
  14. {obstruct-0.4.0 → obstruct-0.5.1}/.idea/obstruct.iml +0 -0
  15. {obstruct-0.4.0 → obstruct-0.5.1}/.idea/vcs.xml +0 -0
  16. {obstruct-0.4.0 → obstruct-0.5.1}/BENCHMARK_TEST.md +0 -0
  17. {obstruct-0.4.0 → obstruct-0.5.1}/pyproject.toml +0 -0
  18. {obstruct-0.4.0 → obstruct-0.5.1}/src/obstruct/__init__.py +0 -0
  19. {obstruct-0.4.0 → obstruct-0.5.1}/src/obstruct/aot/__init__.py +0 -0
  20. {obstruct-0.4.0 → obstruct-0.5.1}/src/obstruct/aot/aot.py +0 -0
  21. {obstruct-0.4.0 → obstruct-0.5.1}/src/obstruct/aot/base.py +0 -0
  22. {obstruct-0.4.0 → obstruct-0.5.1}/src/obstruct/aot/pack.py +0 -0
  23. {obstruct-0.4.0 → obstruct-0.5.1}/src/obstruct/metadata_marks.py +0 -0
  24. {obstruct-0.4.0 → obstruct-0.5.1}/src/obstruct/methods.py +0 -0
  25. {obstruct-0.4.0 → obstruct-0.5.1}/src/obstruct/types/__init__.py +0 -0
  26. {obstruct-0.4.0 → obstruct-0.5.1}/src/obstruct/types/base.py +0 -0
  27. {obstruct-0.4.0 → obstruct-0.5.1}/src/obstruct/types/types.py +0 -0
  28. {obstruct-0.4.0 → obstruct-0.5.1}/src/obstruct/types/types.pyi +0 -0
  29. {obstruct-0.4.0 → obstruct-0.5.1}/test/test.py +0 -0
  30. {obstruct-0.4.0 → obstruct-0.5.1}/uv.lock +0 -0
@@ -4,12 +4,8 @@
4
4
  <option name="autoReloadType" value="SELECTIVE" />
5
5
  </component>
6
6
  <component name="ChangeListManager">
7
- <list default="true" id="b482b6b4-48ce-4be1-bf3c-a72ec254fa35" name="更改" comment="fix: 更新版本号至 0.2.15,修复延迟加载不会应用到类属性的问题">
8
- <change afterPath="$PROJECT_DIR$/BENCHMARK_TEST.md" afterDir="false" />
9
- <change beforePath="$PROJECT_DIR$/src/obstruct/__version__.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/obstruct/__version__.py" afterDir="false" />
10
- <change beforePath="$PROJECT_DIR$/src/obstruct/aot/base.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/obstruct/aot/base.py" afterDir="false" />
7
+ <list default="true" id="b482b6b4-48ce-4be1-bf3c-a72ec254fa35" name="更改" comment="Update README.md">
11
8
  <change beforePath="$PROJECT_DIR$/src/obstruct/aot/unpack.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/obstruct/aot/unpack.py" afterDir="false" />
12
- <change beforePath="$PROJECT_DIR$/test/test_speed.py" beforeDir="false" afterPath="$PROJECT_DIR$/test/test_speed.py" afterDir="false" />
13
9
  </list>
14
10
  <option name="SHOW_DIALOG" value="false" />
15
11
  <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -290,7 +286,47 @@
290
286
  <option name="project" value="LOCAL" />
291
287
  <updated>1786971691114</updated>
292
288
  </task>
293
- <option name="localTasksCounter" value="20" />
289
+ <task id="LOCAL-00020" summary="feat: 添加可选的 post_unpack 钩子&#10;(注意:此功能会导致解包相关功能速度降低,请按需使用)&#10;&#10;+ 更新版本号至 0.4.0">
290
+ <option name="closed" value="true" />
291
+ <created>1787038015671</created>
292
+ <option name="number" value="00020" />
293
+ <option name="presentableId" value="LOCAL-00020" />
294
+ <option name="project" value="LOCAL" />
295
+ <updated>1787038015671</updated>
296
+ </task>
297
+ <task id="LOCAL-00021" summary="chore: 更新测速脚本,添加新增的测试结果">
298
+ <option name="closed" value="true" />
299
+ <created>1787038095094</created>
300
+ <option name="number" value="00021" />
301
+ <option name="presentableId" value="LOCAL-00021" />
302
+ <option name="project" value="LOCAL" />
303
+ <updated>1787038095094</updated>
304
+ </task>
305
+ <task id="LOCAL-00022" summary="feat: 移除了自动生成 slots 的功能,其责任转移给 dataclass&#10;&#10;+ 更新版本号:0.5.0">
306
+ <option name="closed" value="true" />
307
+ <created>1787038912981</created>
308
+ <option name="number" value="00022" />
309
+ <option name="presentableId" value="LOCAL-00022" />
310
+ <option name="project" value="LOCAL" />
311
+ <updated>1787038912981</updated>
312
+ </task>
313
+ <task id="LOCAL-00023" summary="feat: 移除了自动生成 slots 的功能,其责任转移给 dataclass&#10;&#10;+ 更新版本号:0.5.0&#10;+ 更新测试脚本中的逻辑,启用 dataclass 的 slots 功能">
314
+ <option name="closed" value="true" />
315
+ <created>1787038979727</created>
316
+ <option name="number" value="00023" />
317
+ <option name="presentableId" value="LOCAL-00023" />
318
+ <option name="project" value="LOCAL" />
319
+ <updated>1787038979727</updated>
320
+ </task>
321
+ <task id="LOCAL-00024" summary="Update README.md">
322
+ <option name="closed" value="true" />
323
+ <created>1787039079710</created>
324
+ <option name="number" value="00024" />
325
+ <option name="presentableId" value="LOCAL-00024" />
326
+ <option name="project" value="LOCAL" />
327
+ <updated>1787039079710</updated>
328
+ </task>
329
+ <option name="localTasksCounter" value="25" />
294
330
  <servers />
295
331
  </component>
296
332
  <component name="TypeScriptGeneratedFilesManager">
@@ -326,6 +362,11 @@
326
362
  <MESSAGE value="fix: 更新版本号至 0.2.13,修复类变量识别错误的问题" />
327
363
  <MESSAGE value="fix: 更新版本号至 0.2.14,修复 __cendian__ 类变量识别错误的问题" />
328
364
  <MESSAGE value="fix: 更新版本号至 0.2.15,修复延迟加载不会应用到类属性的问题" />
329
- <option name="LAST_COMMIT_MESSAGE" value="fix: 更新版本号至 0.2.15,修复延迟加载不会应用到类属性的问题" />
365
+ <MESSAGE value="feat: 添加可选的 post_unpack 钩子&#10;(注意:此功能会导致解包相关功能速度降低,请按需使用)&#10;&#10;+ 更新版本号至 0.4.0" />
366
+ <MESSAGE value="chore: 更新测速脚本,添加新增的测试结果" />
367
+ <MESSAGE value="feat: 移除了自动生成 slots 的功能,其责任转移给 dataclass&#10;&#10;+ 更新版本号:0.5.0" />
368
+ <MESSAGE value="feat: 移除了自动生成 slots 的功能,其责任转移给 dataclass&#10;&#10;+ 更新版本号:0.5.0&#10;+ 更新测试脚本中的逻辑,启用 dataclass 的 slots 功能" />
369
+ <MESSAGE value="Update README.md" />
370
+ <option name="LAST_COMMIT_MESSAGE" value="Update README.md" />
330
371
  </component>
331
372
  </project>
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: obstruct
3
- Version: 0.4.0
3
+ Version: 0.5.1
4
4
  Author-email: LittleNightSong <LittleNightSongYO@outlook.com>
5
5
  Classifier: Development Status :: 3 - Alpha
6
6
  Classifier: Programming Language :: Python
@@ -50,6 +50,8 @@ _一个简单、纯粹、极速的二进制解析库_
50
50
  - 打包:269.639ns 一次操作
51
51
  - 解包:582.185ns 一次操作
52
52
 
53
+ > 新的测试报告请参见 [BENCHMARK_TEST](BENCHMARK_TEST.md)
54
+
53
55
  ## 安装
54
56
 
55
57
  ```commandline
@@ -88,8 +90,8 @@ if __name__ == '__main__':
88
90
 
89
91
  ```
90
92
 
91
- > [!WARNING]
92
- > 不要在 dataclass 装饰器中使用 `slots=True`,`Struct` 元类已为类型添加了 `__slots__`
93
+ > [!TIP]
94
+ > 建议 dataclass 装饰器中使用 `slots=True` 以加速属性访问和内存效率
93
95
 
94
96
  在上述示例中,你可能发现 `data != restored`,这是浮点数的精度限制导致的。 因此,我们不建议使用浮点数类型,浮点数在二进制传输中也不常见。
95
97
 
@@ -36,6 +36,8 @@ _一个简单、纯粹、极速的二进制解析库_
36
36
  - 打包:269.639ns 一次操作
37
37
  - 解包:582.185ns 一次操作
38
38
 
39
+ > 新的测试报告请参见 [BENCHMARK_TEST](BENCHMARK_TEST.md)
40
+
39
41
  ## 安装
40
42
 
41
43
  ```commandline
@@ -74,8 +76,8 @@ if __name__ == '__main__':
74
76
 
75
77
  ```
76
78
 
77
- > [!WARNING]
78
- > 不要在 dataclass 装饰器中使用 `slots=True`,`Struct` 元类已为类型添加了 `__slots__`
79
+ > [!TIP]
80
+ > 建议 dataclass 装饰器中使用 `slots=True` 以加速属性访问和内存效率
79
81
 
80
82
  在上述示例中,你可能发现 `data != restored`,这是浮点数的精度限制导致的。 因此,我们不建议使用浮点数类型,浮点数在二进制传输中也不常见。
81
83
 
@@ -0,0 +1 @@
1
+ version = "0.5.1"
@@ -183,12 +183,12 @@ def create_unpack_methods(cls: type[Struct]):
183
183
  for n, *_ in array_fields:
184
184
  iter_update_inner.add_code(f'{n}.clear()')
185
185
 
186
- print(unpack.generate_code())
187
- print(update.generate_code())
188
- print(unpack_from.generate_code())
189
- print(update_from.generate_code())
190
- print(iter_unpack.generate_code())
191
- print(iter_update.generate_code())
186
+ # print(unpack.generate_code())
187
+ # print(update.generate_code())
188
+ # print(unpack_from.generate_code())
189
+ # print(update_from.generate_code())
190
+ # print(iter_unpack.generate_code())
191
+ # print(iter_update.generate_code())
192
192
 
193
193
  globals = {
194
194
  v: k for k, v in inner_classes.items() # 翻转字典
@@ -31,29 +31,6 @@ class StructMeta(type):
31
31
  '__cfields__',
32
32
  }
33
33
 
34
- def __new__(cls, name, bases, attrs, *, endian='little'):
35
- slots = set(attrs.get('__slots__', ()))
36
-
37
- annotations = attrs.get('__annotations__')
38
-
39
- if annotations is None:
40
- import annotationlib
41
- annotate = annotationlib.get_annotate_from_class_namespace(attrs)
42
- assert annotate is not None
43
-
44
- annotations = annotationlib.call_annotate_function(
45
- annotate,
46
- format=annotationlib.Format.STRING
47
- )
48
-
49
- slots |= {k for k in annotations.keys()}
50
- slots -= cls.__struct_methods__
51
-
52
- attrs['__slots__'] = slots
53
- attrs['__cendian__'] = endian
54
-
55
- return super().__new__(cls, name, bases, attrs)
56
-
57
34
  def __compile_struct__(cls):
58
35
  from obstruct.methods import to_format_string
59
36
  fields = [
@@ -108,6 +85,9 @@ class Struct(metaclass=StructMeta):
108
85
  __cstruct__: ClassVar[struct.Struct]
109
86
  __cendian__: ClassVar[str]
110
87
 
88
+ def __init_subclass__(cls, *, endian='little') -> None:
89
+ cls.__cendian__ = endian
90
+
111
91
  if typing.TYPE_CHECKING:
112
92
  def pack(self) -> bytes:
113
93
  ...
@@ -10,7 +10,7 @@ def run_iterator(iterator):
10
10
  [i for i in iterator]
11
11
 
12
12
 
13
- @dataclasses.dataclass()
13
+ @dataclasses.dataclass(slots=True)
14
14
  class MyStruct(obs.Struct):
15
15
  a: int
16
16
  b: int
@@ -30,7 +30,7 @@ class MyStruct(obs.Struct):
30
30
  is_post_unpack_called = True
31
31
 
32
32
 
33
- @dataclasses.dataclass()
33
+ @dataclasses.dataclass(slots=True)
34
34
  class AnotherStruct(obs.Struct):
35
35
  x: MyStruct
36
36
  y: Annotated[array[int], 100]
@@ -1 +0,0 @@
1
- version = "0.4.0"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes