Skip to content

Commit dc0795c

Browse files
committed
[binary] Add composers and partial composers
1 parent ae89bda commit dc0795c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1051
-40
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,6 @@ cython_debug/
144144

145145
# setuptools_scm version
146146
src/blk/_version.py
147+
148+
# drawio backup
149+
docs/**/*.drawio.bkp

docs/Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = source
9+
BUILDDIR = build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/make.bat

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=source
11+
set BUILDDIR=build
12+
13+
if "%1" == "" goto help
14+
15+
%SPHINXBUILD% >NUL 2>NUL
16+
if errorlevel 9009 (
17+
echo.
18+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19+
echo.installed, then set the SPHINXBUILD environment variable to point
20+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
21+
echo.may add the Sphinx directory to PATH.
22+
echo.
23+
echo.If you don't have Sphinx installed, grab it from
24+
echo.http://sphinx-doc.org/
25+
exit /b 1
26+
)
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

docs/source/binary_blk_files.rst

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
==================
2+
Двоичные файлы BLK
3+
==================
4+
5+
-------------
6+
Файл типа FAT
7+
-------------
8+
9+
Автономный файл.
10+
11+
Примеры:
12+
13+
* ``WarThunder/game.vromfs.bin/danetlibs/route_prober/templates/route_prober.blk``
14+
* ``tests/samples/section_fat.blk``
15+
16+
.. drawio-image:: diagrams/section_fat.drawio
17+
18+
BlkType.FAT
19+
Byte, тип файла 1.
20+
21+
Names container
22+
Контейнер имен.
23+
24+
Blocks container
25+
Контейнер блоков.
26+
27+
Диаграмма для ``tests/samples/section_fat.blk``
28+
29+
.. drawio-image:: diagrams/section_fat_dump.drawio
30+
31+
-----------------
32+
Файл типа FAT_ZST
33+
-----------------
34+
35+
Автономный файл со сжатым zstd контейнером.
36+
37+
--------------
38+
Файл типа SLIM
39+
--------------
40+
41+
Неавтономный файл, разделяющий последовательность имен.
42+
43+
------------------
44+
Файл типа SLIM_ZST
45+
------------------
46+
47+
Неавтономный файл, разделяющий последовательность имен со сжатым zstd контейнером.
48+
49+
-----------------------
50+
Файл типа SLIM_ZST_DICT
51+
-----------------------
52+
53+
Неавтономный файл, разделяющий последовательность имен со сжатым zstd контейнером, с использованием словаря.
54+
55+
-------------
56+
Файл типа BBF
57+
-------------
58+
59+
Автономный файл старого формата.
60+
61+
------------------
62+
Файл типа BBF_ZLIB
63+
------------------
64+
65+
Автономный файл старого формата со сжатым zlib контейнером.
66+
67+
-------
68+
Файл NM
69+
-------
70+
71+
Файл разделяемой последовательности имен.
72+
73+
Примеры:
74+
75+
* ``WarThunder/gui.vromfs.bin/nm``
76+
* ``tests/samples/nm``
77+
78+
.. drawio-image:: diagrams/nm.drawio
79+
80+
Table digest
81+
64-битный идентификатор таблицы. Алгоритм построения неизвестен.
82+
83+
Dict digest
84+
256-битный идентификатор таблицы. Алгоритм построения неизвестен.
85+
86+
Compressed names container
87+
Контейнер имен, сжатый по алгоритму zstandard без использования словаря.
88+
89+
Диаграмма для ``tests/samples/nm``
90+
91+
.. drawio-image:: diagrams/nm_dump.drawio
92+
93+
94+
Контейнер имен
95+
==============
96+
97+
Блок контейнера имен.
98+
99+
.. drawio-image:: diagrams/names_container.drawio
100+
101+
Names count
102+
VarInt, число строк в последовательности.
103+
104+
Names array size
105+
VarInt, размер массива строк
106+
107+
Names array
108+
Массив C-строк.
109+
110+
Диаграмма для ``tests/samples/names_container``
111+
112+
.. drawio-image:: diagrams/names_container_dump.drawio
113+
114+
.. list-table:: Карта имен
115+
:header-rows: 1
116+
:align: left
117+
118+
* - Индекс
119+
- Имя | Строка
120+
* - 0
121+
- ``'vec4f'``
122+
* - 1
123+
- ``'int'``
124+
* - 2
125+
- ``'long'``
126+
* - 3
127+
- ``'alpha'``
128+
* - 4
129+
- ``'str'``
130+
* - 5
131+
- ``'bool'``
132+
* - 6
133+
- ``'color'``
134+
* - 7
135+
- ``'gamma'``
136+
* - 8
137+
- ``'vec2i'``
138+
* - 9
139+
- ``'vec2f'``
140+
* - a
141+
- ``'transform'``
142+
* - b
143+
- ``'beta'``
144+
* - c
145+
- ``'float'``
146+
* - d
147+
- ``'vec3f'``
148+
* - e
149+
- ``'hello'``
150+
151+
152+

docs/source/conf.py

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
#
13+
# import os
14+
# import sys
15+
# sys.path.insert(0, os.path.abspath('.'))
16+
17+
18+
# -- Project information -----------------------------------------------------
19+
20+
project = 'BLK Notes'
21+
copyright = '2022, kotiq'
22+
author = 'kotiq'
23+
24+
25+
# -- General configuration ---------------------------------------------------
26+
27+
# Add any Sphinx extension module names here, as strings. They can be
28+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
29+
# ones.
30+
extensions = [
31+
'sphinxcontrib.drawio'
32+
]
33+
34+
# Add any paths that contain templates here, relative to this directory.
35+
templates_path = ['_templates']
36+
37+
# The language for content autogenerated by Sphinx. Refer to documentation
38+
# for a list of supported languages.
39+
#
40+
# This is also used if you do content translation via gettext catalogs.
41+
# Usually you set "language" from the command line for these cases.
42+
language = 'ru'
43+
44+
# List of patterns, relative to source directory, that match files and
45+
# directories to ignore when looking for source files.
46+
# This pattern also affects html_static_path and html_extra_path.
47+
exclude_patterns = []
48+
49+
50+
# -- Options for HTML output -------------------------------------------------
51+
52+
# The theme to use for HTML and HTML Help pages. See the documentation for
53+
# a list of builtin themes.
54+
#
55+
html_theme = 'alabaster'
56+
57+
html_theme_options = {
58+
'page_width': 'auto',
59+
'body_max_width': 'auto',
60+
}
61+
62+
# Add any paths that contain custom static files (such as style sheets) here,
63+
# relative to this directory. They are copied after the builtin static files,
64+
# so a file named "default.css" will overwrite the builtin "default.css".
65+
html_static_path = ['_static']
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<mxfile host="Electron" modified="2022-07-03T13:00:23.169Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/19.0.3 Chrome/102.0.5005.63 Electron/19.0.3 Safari/537.36" etag="ilR4mBwwK4c0E6g9iQjZ" version="19.0.3" type="device"><diagram id="SoT3GUOYtWTpkWzOqNjb" name="Page-1">1ZTBasMwDIafJsdB4qyhO25dt106Njoo7DLcRLUNThxct0n29JMXJWkohfYwRi9B+iRL1m+RIJ7l9bPlpVyYDHTAwqwO4seAscmE4deDhsD0rgXCqqxF0QCW6hsIhkR3KoPtKNEZo50qxzA1RQGpGzFuranGaRujx11LLuAILFOuj+lKZU62dDoJB/4CSsiucxRSJOddMoGt5JmpDlA8D+KZNca1Vl7PQHvtOl3ac08nov3FLBTunAP1R/kWvt8n689VvBGLr7CQ6xuqsud6RwMHLNFY72GNhvDGK8/xAbzCO2xEUWzTJ9B4ruk0q6RysCx56v0K1wKTpMs1ehGaXCtRoJ3ixcH2BfZgHdQnh4t6yXDVwOTgbIMpdOCWRG7GbjU8WZQQkwfP1eVx2hLRFx6ERIO0vEBXdr6uuKXcT7L1u38d8k7/W974YnmvQteI/Z2w6A7/mt/YwQ87nv8A</diagram></mxfile>

docs/source/diagrams/names_container_dump.drawio

+1
Large diffs are not rendered by default.

docs/source/diagrams/nm.drawio

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<mxfile host="Electron" modified="2022-07-03T12:47:42.663Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/19.0.3 Chrome/102.0.5005.63 Electron/19.0.3 Safari/537.36" etag="PKUUeFgEnd1Gdu7tGYrR" version="19.0.3" type="device"><diagram id="WXj8gqkEhlGfL43AjHRx" name="Page-1">1ZRNb4MwDIZ/DcdKEEo/rqXdp3bqpJ1T4oVUCUEhLbBfP1MCFFVVt8M09YLs145DHlv2wlhVj4bm6ZtmID3is8oL1x4hUUTw2wi1ExbLVuBGsFYKBmErvsCJvlMPgkExSrRaSyvysZjoLIPEjjRqjC7HaZ9ajm/NKYcLYZtQeal+CGbTVl1E/qA/geBpd3Pgu4iiXbITipQyXZ5J4cYLY6O1bS1VxSAbdh2X9tzDlWj/YwYy+5MDZMXWsXieL7PJC4f9PNwXr5NpW+VI5cE92CMzifVWOzR4Y7zTHcLADgoOhe3CeE+f4d5n6w5amQoL25wmjV/iXGBSapVEL0CTSsEztBP8czB9gSMYC9XV1wU9M5w10AqsqTHFHZg6yvXYLYeeka4z6Vm/ujzqxoT3hQeSaDiYvwAb3Qa7Fjivd8Z18d9cZ7e5xlrlBooCGCZmVOH6OO0HS0WGWO4DdED+jjS6w9o5xc52d7j5Bg==</diagram></mxfile>

docs/source/diagrams/nm_dump.drawio

+1
Large diffs are not rendered by default.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<mxfile host="Electron" modified="2022-07-04T09:33:10.521Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/19.0.3 Chrome/102.0.5005.63 Electron/19.0.3 Safari/537.36" etag="81zZHDmrz2QEY4UwChmQ" version="19.0.3" type="device"><diagram id="guvB41xKFE58ETjuSDFe" name="Page-1">1VTLTsMwEPyaHIvSuAr0SJ8BCTi0iLNJltiqE1uu2yR8PZvGzkMVohwQ6sm7M+O1d7yyR+ZZudZUsSeZgPACPyk9svCCYDz2A1xqpGqQcHLbAKnmiRV1wIZ/ggV9ix54AvuB0EgpDFdDMJZ5DrEZYFRrWQxlH1IMT1U0hTNgE1Nxjr7xxDCLhr7fERHwlNmjp47IqBNbYM9oIoseRJYemWspTRNl5RxEbZ7zpdm3+oZtL6YhN5dsmOaRYi9ksVXRQ3X0w8dXORrZKkcqDrZhLwgF1pu9Y5DWwUzstpWCm9X91nF4SEvb5kzlHCsYN7BRNK7zAqcCRcxkArMxhlTwNMc4xmuDbgv0+3CXAm2g7EG2rzXIDIyuUGLZibW4GqZF78HcK7DeWzkdtTOStoU7GzGwTv7C1eBnV59phmN9mltDeY5OXIe3d//tLblkYmW8u0ZzWyf/wF1Mu7/mxPV+bLL8Ag==</diagram></mxfile>

docs/source/diagrams/section_fat_dump.drawio

+1
Large diffs are not rendered by default.

docs/source/index.rst

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.. BLK Notes documentation master file, created by
2+
sphinx-quickstart on Sun Jul 3 16:07:04 2022.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
Welcome to BLK Notes's documentation!
7+
=====================================
8+
9+
.. toctree::
10+
:maxdepth: 2
11+
:caption: Contents:
12+
13+
binary_blk_files
14+
15+
16+
17+
Indices and tables
18+
==================
19+
20+
* :ref:`genindex`
21+
* :ref:`modindex`
22+
* :ref:`search`

requirements-dev.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
-r requirements-test.txt
2+
sphinx==4.1.2
3+
sphinxcontrib-drawio==0.0.16
24
tox==3.24.4
3-

src/blk/binary/__init__.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
11
from .error import *
2+
from .constants import *
23
from .constructor import *
34
from .bbf_constructor import *
45

56
__all__ = [
7+
'BlkType',
68
'ComposeError',
79
'ConstructError',
810
'Fat',
911
'InvNames',
1012
'SerializeError',
1113
'compose_bbf',
1214
'compose_bbf_zlib',
13-
'compose_partial_fat',
14-
'compose_names_data',
1515
'compose_partial_bbf',
1616
'compose_partial_bbf_zlib',
17+
'compose_partial_fat',
18+
'compose_partial_fat_zst',
19+
'compose_partial_names',
1720
'compose_partial_slim',
21+
'compose_partial_slim_zst',
22+
'compose_slim',
23+
'compose_slim_zst',
24+
'compose_slim_zst_dict',
1825
'serialize_bbf',
1926
'serialize_bbf_zlib',
20-
'serialize_fat_data',
21-
'serialize_names_data',
22-
'serialize_slim_data'
27+
'serialize_fat',
28+
'serialize_fat_zst',
29+
'serialize_partial_fat',
30+
'serialize_partial_names',
31+
'serialize_partial_slim',
32+
'serialize_slim_zst',
33+
'serialize_slim_zst_dict',
2334
]

src/blk/binary/constants.py

+23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from enum import IntEnum
12
from blk.types import Bool, Color, Float, Float2, Float3, Float4, Float12, Int, Int2, Int3, Long, Section, Str
23

34
__all__ = [
5+
'BlkType',
46
'codes_types_map',
57
'types_codes_map'
68
]
@@ -23,3 +25,24 @@
2325
}
2426

2527
codes_types_map = {v: k for k, v in types_codes_map.items()}
28+
29+
30+
class BlkType(IntEnum):
31+
BBF = 0
32+
FAT = 1
33+
FAT_ZST = 2
34+
SLIM = 3
35+
SLIM_ZST = 4
36+
SLIM_ZST_DICT = 5
37+
OTHER = -1
38+
39+
@classmethod
40+
def from_byte(cls, byte: bytes) -> 'BlkType':
41+
return {
42+
0: cls.BBF, # BBF | BBZ
43+
1: cls.FAT,
44+
2: cls.FAT_ZST,
45+
3: cls.SLIM,
46+
4: cls.SLIM_ZST,
47+
5: cls.SLIM_ZST_DICT,
48+
}.get(byte[0], cls.OTHER)

0 commit comments

Comments
 (0)