Skip to content

Commit 9227603

Browse files
committed
Docs: Add documents and code example for referencing constants as option values
1 parent d894756 commit 9227603

File tree

4 files changed

+200
-159
lines changed

4 files changed

+200
-159
lines changed

docs/language.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ We can define an option in global scope and message scopes, like this:
571571

572572
option name = value
573573

574-
The value of an option can be an integer, string or boolean, according to the option itself.
574+
The value of an option can be an integer, string, boolean or ``constant``, according to the option itself.
575575

576576
For an example, there's an option named ``max_bytes`` to constraint message sizes, the
577577
bitproto compiler will report an error and refuse to compile if the declared message's
@@ -584,6 +584,19 @@ size is larger than the configured value:
584584
byte[4] field = 1 // Violated max_bytes constraint
585585
}
586586

587+
Another example that references constants as option values:
588+
589+
.. sourcecode:: bitproto
590+
591+
const MAX_MESSAGE_LENGTH = 128
592+
const HEADER_LENGTH = 5
593+
const MAX_PAYLOAD_LENGTH = MAX_MESSAGE_LENGTH - HEADER_LENGTH
594+
595+
message SomeMessage {
596+
option max_bytes = MAX_PAYLOAD_LENGTH
597+
}
598+
599+
587600
Full table of options supported:
588601

589602
``c.struct_packing_alignment``

docs/locales/zh/LC_MESSAGES/changelog.po

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,105 +8,122 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: bitproto 0.4.0\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2023-05-22 21:23+0800\n"
11+
"POT-Creation-Date: 2025-03-22 16:17+0800\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"
1515
"MIME-Version: 1.0\n"
1616
"Content-Type: text/plain; charset=utf-8\n"
1717
"Content-Transfer-Encoding: 8bit\n"
18-
"Generated-By: Babel 2.12.1\n"
18+
"Generated-By: Babel 2.17.0\n"
1919

20-
#: ../../changelog.rst:2 eb5e577b5cca451f97c84e6697bf5395
20+
#: ../../changelog.rst:2 bd0c49799ad1472b9ebc5a93eae789ae
2121
msgid "Changelog"
2222
msgstr "版本历史"
2323

24-
#: ../../../changes.rst:4 fc5a94d17a314c589b3622ad0c32e5a0
24+
#: ../../../changes.rst:4 4ca3aa397b074fb7a87296b215f52ecb
25+
msgid "Version 1.1.1"
26+
msgstr ""
27+
28+
#: ../../../changes.rst:8 61227587c4e443038089921f7bf8584f
29+
msgid ""
30+
"Fix bug: enum importing other bitproto's field name generation bug. #53 "
31+
"#52"
32+
msgstr ""
33+
34+
#: ../../../changes.rst:9 66206e28775a4993a98af4b796bd3097
35+
msgid ""
36+
"Fix bug: import statements of bitprotos should be placed ahead of other "
37+
"declarations. #53"
38+
msgstr ""
39+
40+
#: ../../../changes.rst:12 9c595ec0cf7f4e21b9cab4878149574c
2541
msgid "Version 1.1.0"
2642
msgstr ""
2743

28-
#: ../../../changes.rst:8 266428222faa4853ae12a6fe4a43b374
44+
#: ../../../changes.rst:16 668377b7aead4b6e9dfe5650f07f550d
2945
msgid ""
3046
"Performance improvements for C bitprotolib, 40~60us improvement per call "
3147
"on stm32. PR #48."
3248
msgstr ""
3349

34-
#: ../../../changes.rst:9 3242e95c31e649849edab6676af21f4d
50+
#: ../../../changes.rst:17 351457b1434647ff926e98fe7fb00c5a
3551
msgid ""
3652
"Fix Python nested message ``__post_init___`` function code generation. PR"
3753
" #48, commit 73f4b01."
3854
msgstr ""
3955

40-
#: ../../../changes.rst:12 fc5a94d17a314c589b3622ad0c32e5a0
56+
#: ../../../changes.rst:20 24745d925dd0496c8a1dd647e7b7225f
4157
msgid "Version 1.0.1"
4258
msgstr ""
4359

44-
#: ../../../changes.rst:16 c7bc4aba599d47b78b5b95e56f41257d
60+
#: ../../../changes.rst:24 c9cede67a4354f85a113fe9802d7c3f1
4561
msgid "Add support for Python 3.11"
4662
msgstr ""
4763

48-
#: ../../../changes.rst:19 fc5a94d17a314c589b3622ad0c32e5a0
64+
#: ../../../changes.rst:27 33d884cb4ef54a7e80d5c425391b372c
4965
msgid "Version 1.0.0"
5066
msgstr ""
5167

52-
#: ../../../changes.rst:23 c894eb85f9834f1b837622fd859c7e98
68+
#: ../../../changes.rst:31 3592669cb8e847c49cea8a365c2c3a5f
5369
msgid "First fully release version"
5470
msgstr "第一次发布 1.0 版本"
5571

56-
#: ../../../changes.rst:28 30bc2f453f9a4e4daec1f2b082a6ac91
72+
#: ../../../changes.rst:36 b3a828ec2f7a44a4b6401d53455fffc6
5773
msgid "Version 0.4.6"
5874
msgstr ""
5975

60-
#: ../../../changes.rst:30 9e9740e4c92e4ed595194bd543ebe147
76+
#: ../../../changes.rst:38 4f633212411841cd8396ddd38a9f24cc
6177
msgid "Support signed integers with arbitrary bits, e.g. int24 PR#45."
6278
msgstr "支持任意比特数目的有符号整数类型 例如 int24, 见 PR#45"
6379

64-
#: ../../../changes.rst:35 30bc2f453f9a4e4daec1f2b082a6ac91
80+
#: ../../../changes.rst:43 90f0ae1491a84c41a2b9c5dc0e66f845
6581
msgid "Version 0.4.5"
6682
msgstr ""
6783

68-
#: ../../../changes.rst:37 3ba33408fbab4e6e8fa4bd1348e776a9
84+
#: ../../../changes.rst:45 5390534c2c094a6b881c30f62d565d17
6985
msgid ""
7086
"Use Python IntEnum for enum generation (respecting backward "
7187
"compatibility) PR#41."
7288
msgstr ""
7389

74-
#: ../../../changes.rst:42 dc7770b7fd674da18fa53f58fea0f06f
90+
#: ../../../changes.rst:50 3bfcca062ff44f87aea90bf7a6f339b1
7591
msgid "Version 0.4.4"
7692
msgstr ""
7793

78-
#: ../../../changes.rst:44 ee1e046b6272442181a755b5b744d6ba
94+
#: ../../../changes.rst:52 c5a2117f96e4413da42ee13729394184
7995
msgid "Minor fix compiler setup.py path issue."
8096
msgstr ""
8197

82-
#: ../../../changes.rst:49 2cd432670b154c19a01259f94cb33bc3
98+
#: ../../../changes.rst:57 86561ffe65894180a12c77dd57d8172f
8399
msgid "Version 0.4.2"
84100
msgstr ""
85101

86-
#: ../../../changes.rst:51 a8406cdecd1d4dfc94ad9cebc4c927b5
102+
#: ../../../changes.rst:59 bc317a756c0f44999c0c22be675a7deb
87103
msgid "Allow using ``type`` as message field name, fixes issue #39."
88104
msgstr ""
89105

90-
#: ../../../changes.rst:56 fc5a94d17a314c589b3622ad0c32e5a0
106+
#: ../../../changes.rst:64 a00793c65d2c427f9b81c1ccab8ad424
91107
msgid "Version 0.4.0"
92108
msgstr ""
93109

94-
#: ../../../changes.rst:58 3c499990cd38434f932a3558376617c5
110+
#: ../../../changes.rst:66 b0917dbfc0524e74ba171e75741e97e2
95111
msgid ""
96112
"Add support for ``message`` and ``enum`` extensiblity for protocol "
97113
"forward compatibility."
98114
msgstr ""
99115

100-
#: ../../../changes.rst:59 ad10bcd6f05a4e5187b2d8ba2f3e5235
116+
#: ../../../changes.rst:67 95abb35c9fcd4d449a32519fd31ac1aa
101117
msgid "Cut down the code size of generated language-specific files."
102118
msgstr ""
103119

104-
#: ../../../changes.rst:60 a2e47a95cb5c4f44ac3a9d965d8d719c
120+
#: ../../../changes.rst:68 ccf790e19105464b9c222eb7d5916f8d
105121
msgid "Refactor the bitproto compiler."
106122
msgstr ""
107123

108-
#: ../../../changes.rst:61 480040dd74284c97acfb4dcc47354779
124+
#: ../../../changes.rst:69 6f93b6bbf73748d4b801a715f0cba57b
109125
msgid ""
110126
"Refactor the bitproto serialization mechanism, using language-specific "
111127
"libraries instead of pure compiler-generated files."
112128
msgstr ""
129+

0 commit comments

Comments
 (0)