Skip to content

Commit af35ddf

Browse files
committed
bump v1.1.2: (Feature) Allow using constants as option values. ISSUE #61, PR #63
1 parent 9227603 commit af35ddf

File tree

11 files changed

+303
-28
lines changed

11 files changed

+303
-28
lines changed

changes.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
.. currentmodule:: bitproto
22

3+
Version 1.1.2
4+
-------------
5+
6+
.. _version-1.1.2
7+
8+
- Feature: Allow using constants as option values. ISSUE #61, PR #63
9+
310
Version 1.1.1
411
-------------
512

compiler/bitproto/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
99
"""
1010

11-
__version__ = "1.1.1"
11+
__version__ = "1.1.2"
1212
__description__ = "bit level data interchange format."

docs/language.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ 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:
587+
Another example that references constants as option values (supported since v1.1.2):
588588

589589
.. sourcecode:: bitproto
590590

docs/locales/zh/LC_MESSAGES/changelog.po

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: bitproto 0.4.0\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2025-03-22 16:17+0800\n"
11+
"POT-Creation-Date: 2025-03-22 16:32+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"
@@ -22,106 +22,114 @@ msgid "Changelog"
2222
msgstr "版本历史"
2323

2424
#: ../../../changes.rst:4 4ca3aa397b074fb7a87296b215f52ecb
25+
msgid "Version 1.1.2"
26+
msgstr "Version 1.1.2"
27+
28+
#: ../../../changes.rst:8 427ec549afc64dd3ba6e4efb7ba67165
29+
msgid "Feature: Allow using constants as option values. ISSUE #61, PR #63"
30+
msgstr ""
31+
32+
#: ../../../changes.rst:11 4ca3aa397b074fb7a87296b215f52ecb
2533
msgid "Version 1.1.1"
2634
msgstr ""
2735

28-
#: ../../../changes.rst:8 61227587c4e443038089921f7bf8584f
36+
#: ../../../changes.rst:15 61227587c4e443038089921f7bf8584f
2937
msgid ""
3038
"Fix bug: enum importing other bitproto's field name generation bug. #53 "
3139
"#52"
3240
msgstr ""
3341

34-
#: ../../../changes.rst:9 66206e28775a4993a98af4b796bd3097
42+
#: ../../../changes.rst:16 66206e28775a4993a98af4b796bd3097
3543
msgid ""
3644
"Fix bug: import statements of bitprotos should be placed ahead of other "
3745
"declarations. #53"
3846
msgstr ""
3947

40-
#: ../../../changes.rst:12 9c595ec0cf7f4e21b9cab4878149574c
48+
#: ../../../changes.rst:19 9c595ec0cf7f4e21b9cab4878149574c
4149
msgid "Version 1.1.0"
4250
msgstr ""
4351

44-
#: ../../../changes.rst:16 668377b7aead4b6e9dfe5650f07f550d
52+
#: ../../../changes.rst:23 668377b7aead4b6e9dfe5650f07f550d
4553
msgid ""
4654
"Performance improvements for C bitprotolib, 40~60us improvement per call "
4755
"on stm32. PR #48."
4856
msgstr ""
4957

50-
#: ../../../changes.rst:17 351457b1434647ff926e98fe7fb00c5a
58+
#: ../../../changes.rst:24 351457b1434647ff926e98fe7fb00c5a
5159
msgid ""
5260
"Fix Python nested message ``__post_init___`` function code generation. PR"
5361
" #48, commit 73f4b01."
5462
msgstr ""
5563

56-
#: ../../../changes.rst:20 24745d925dd0496c8a1dd647e7b7225f
64+
#: ../../../changes.rst:27 24745d925dd0496c8a1dd647e7b7225f
5765
msgid "Version 1.0.1"
5866
msgstr ""
5967

60-
#: ../../../changes.rst:24 c9cede67a4354f85a113fe9802d7c3f1
68+
#: ../../../changes.rst:31 c9cede67a4354f85a113fe9802d7c3f1
6169
msgid "Add support for Python 3.11"
6270
msgstr ""
6371

64-
#: ../../../changes.rst:27 33d884cb4ef54a7e80d5c425391b372c
72+
#: ../../../changes.rst:34 33d884cb4ef54a7e80d5c425391b372c
6573
msgid "Version 1.0.0"
6674
msgstr ""
6775

68-
#: ../../../changes.rst:31 3592669cb8e847c49cea8a365c2c3a5f
76+
#: ../../../changes.rst:38 3592669cb8e847c49cea8a365c2c3a5f
6977
msgid "First fully release version"
7078
msgstr "第一次发布 1.0 版本"
7179

72-
#: ../../../changes.rst:36 b3a828ec2f7a44a4b6401d53455fffc6
80+
#: ../../../changes.rst:43 b3a828ec2f7a44a4b6401d53455fffc6
7381
msgid "Version 0.4.6"
7482
msgstr ""
7583

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

80-
#: ../../../changes.rst:43 90f0ae1491a84c41a2b9c5dc0e66f845
88+
#: ../../../changes.rst:50 90f0ae1491a84c41a2b9c5dc0e66f845
8189
msgid "Version 0.4.5"
8290
msgstr ""
8391

84-
#: ../../../changes.rst:45 5390534c2c094a6b881c30f62d565d17
92+
#: ../../../changes.rst:52 5390534c2c094a6b881c30f62d565d17
8593
msgid ""
8694
"Use Python IntEnum for enum generation (respecting backward "
8795
"compatibility) PR#41."
8896
msgstr ""
8997

90-
#: ../../../changes.rst:50 3bfcca062ff44f87aea90bf7a6f339b1
98+
#: ../../../changes.rst:57 3bfcca062ff44f87aea90bf7a6f339b1
9199
msgid "Version 0.4.4"
92100
msgstr ""
93101

94-
#: ../../../changes.rst:52 c5a2117f96e4413da42ee13729394184
102+
#: ../../../changes.rst:59 c5a2117f96e4413da42ee13729394184
95103
msgid "Minor fix compiler setup.py path issue."
96104
msgstr ""
97105

98-
#: ../../../changes.rst:57 86561ffe65894180a12c77dd57d8172f
106+
#: ../../../changes.rst:64 86561ffe65894180a12c77dd57d8172f
99107
msgid "Version 0.4.2"
100108
msgstr ""
101109

102-
#: ../../../changes.rst:59 bc317a756c0f44999c0c22be675a7deb
110+
#: ../../../changes.rst:66 bc317a756c0f44999c0c22be675a7deb
103111
msgid "Allow using ``type`` as message field name, fixes issue #39."
104112
msgstr ""
105113

106-
#: ../../../changes.rst:64 a00793c65d2c427f9b81c1ccab8ad424
114+
#: ../../../changes.rst:71 a00793c65d2c427f9b81c1ccab8ad424
107115
msgid "Version 0.4.0"
108116
msgstr ""
109117

110-
#: ../../../changes.rst:66 b0917dbfc0524e74ba171e75741e97e2
118+
#: ../../../changes.rst:73 b0917dbfc0524e74ba171e75741e97e2
111119
msgid ""
112120
"Add support for ``message`` and ``enum`` extensiblity for protocol "
113121
"forward compatibility."
114122
msgstr ""
115123

116-
#: ../../../changes.rst:67 95abb35c9fcd4d449a32519fd31ac1aa
124+
#: ../../../changes.rst:74 95abb35c9fcd4d449a32519fd31ac1aa
117125
msgid "Cut down the code size of generated language-specific files."
118126
msgstr ""
119127

120-
#: ../../../changes.rst:68 ccf790e19105464b9c222eb7d5916f8d
128+
#: ../../../changes.rst:75 ccf790e19105464b9c222eb7d5916f8d
121129
msgid "Refactor the bitproto compiler."
122130
msgstr ""
123131

124-
#: ../../../changes.rst:69 6f93b6bbf73748d4b801a715f0cba57b
132+
#: ../../../changes.rst:76 6f93b6bbf73748d4b801a715f0cba57b
125133
msgid ""
126134
"Refactor the bitproto serialization mechanism, using language-specific "
127135
"libraries instead of pure compiler-generated files."

docs/locales/zh/LC_MESSAGES/language.po

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: bitproto 0.4.0\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2025-03-22 16:23+0800\n"
11+
"POT-Creation-Date: 2025-03-22 16:31+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"
@@ -547,8 +547,11 @@ msgid ""
547547
msgstr "具体来说,消息有一个选项叫做 ``max_bytes`` 来约束消息的大小,当我们设计的消息的大小超出这个选项配置的值时,编译器则会报错,拒绝编译:"
548548

549549
#: ../../language.rst:587 9fd60b26e8a04d44b5f942e76e414c1a
550-
msgid "Another example that references constants as option values:"
551-
msgstr "另一个引用常量来作为 option 值的例子:"
550+
#, fuzzy
551+
msgid ""
552+
"Another example that references constants as option values (supported "
553+
"since v1.1.2):"
554+
msgstr "另一个引用常量来作为 option 值的例子 (v1.1.2 新增的支持):"
552555

553556
#: ../../language.rst:600 34dae32f4fe744639519fb4cc0df5e12
554557
msgid "Full table of options supported:"

test1/base.bitproto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
proto base
2+
3+
const MAX_MESSAGE_LENGTH = 6;
4+
const HEADER_LENGTH = 5;
5+
const MAX_PAYLOAD_LENGTH = MAX_MESSAGE_LENGTH - HEADER_LENGTH;

test1/base_bp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Code generated by bitproto. DO NOT EDIT.
2+
3+
#include "bitproto.h"
4+
#include "base_bp.h"

test1/base_bp.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Code generated by bitproto. DO NOT EDIT.
2+
3+
#ifndef __BITPROTO__BASE_H__
4+
#define __BITPROTO__BASE_H__ 1
5+
6+
#include <inttypes.h>
7+
#include <stddef.h>
8+
#include <stdint.h>
9+
#ifndef __cplusplus
10+
#include <stdbool.h>
11+
#endif
12+
13+
#include "bitproto.h"
14+
15+
#if defined(__cplusplus)
16+
extern "C" {
17+
#endif
18+
19+
#define MAX_MESSAGE_LENGTH 6
20+
21+
#define HEADER_LENGTH 5
22+
23+
#define MAX_PAYLOAD_LENGTH 1
24+
25+
#if defined(__cplusplus)
26+
}
27+
#endif
28+
29+
#endif

test1/test.bitproto

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
proto test
2+
3+
import base "base.bitproto"
4+
5+
message MyMessage {
6+
option max_bytes = base.MAX_MESSAGE_LENGTH; // 128
7+
//... // Header contents
8+
byte[base.MAX_PAYLOAD_LENGTH] payload = 3;
9+
}
10+
11+
message MyPayload {
12+
option max_bytes = base.MAX_PAYLOAD_LENGTH; // 123
13+
}
14+
15+
message MyOtherPayload {
16+
option max_bytes = base.MAX_PAYLOAD_LENGTH; // 123
17+
}

test1/test_bp.c

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Code generated by bitproto. DO NOT EDIT.
2+
3+
#include "bitproto.h"
4+
#include "test_bp.h"
5+
6+
void BpXXXProcessArrayMyMessage3(void *data, struct BpProcessorContext *ctx) {
7+
struct BpArrayDescriptor descriptor = BpArrayDescriptor(false, 1, BpByte());
8+
BpEndecodeArray(&descriptor, ctx, data);
9+
}
10+
11+
void BpXXXJsonFormatArrayMyMessage3(void *data, struct BpJsonFormatContext *ctx) {
12+
struct BpArrayDescriptor descriptor = BpArrayDescriptor(false, 1, BpByte());
13+
BpJsonFormatArray(&descriptor, ctx, data);
14+
}
15+
16+
void BpFieldDescriptorsInitMyMessage(struct MyMessage *m, struct BpMessageFieldDescriptor *fds) {
17+
fds[0] = BpMessageFieldDescriptor((void *)&(m->payload), BpArray(8, 1 * sizeof(unsigned char), BpXXXProcessArrayMyMessage3, BpXXXJsonFormatArrayMyMessage3), "payload");
18+
}
19+
20+
void BpXXXProcessMyMessage(void *data, struct BpProcessorContext *ctx) {
21+
struct MyMessage *m = (struct MyMessage *)(data);
22+
struct BpMessageFieldDescriptor field_descriptors[1];
23+
BpFieldDescriptorsInitMyMessage(m, field_descriptors);
24+
struct BpMessageDescriptor descriptor = BpMessageDescriptor(false, 1, 8, field_descriptors);
25+
BpEndecodeMessage(&descriptor, ctx, data);
26+
}
27+
28+
void BpXXXJsonFormatMyMessage(void *data, struct BpJsonFormatContext *ctx) {
29+
struct MyMessage *m = (struct MyMessage *)(data);
30+
struct BpMessageFieldDescriptor field_descriptors[1];
31+
BpFieldDescriptorsInitMyMessage(m, field_descriptors);
32+
struct BpMessageDescriptor descriptor = BpMessageDescriptor(false, 1, 8, field_descriptors);
33+
BpJsonFormatMessage(&descriptor, ctx, data);
34+
}
35+
36+
int EncodeMyMessage(struct MyMessage *m, unsigned char *s) {
37+
struct BpProcessorContext ctx = BpProcessorContext(true, s);
38+
BpXXXProcessMyMessage((void *)m, &ctx);
39+
return 0;
40+
}
41+
42+
int DecodeMyMessage(struct MyMessage *m, unsigned char *s) {
43+
struct BpProcessorContext ctx = BpProcessorContext(false, s);
44+
BpXXXProcessMyMessage((void *)m, &ctx);
45+
return 0;
46+
}
47+
48+
int JsonMyMessage(struct MyMessage *m, char *s) {
49+
struct BpJsonFormatContext ctx = BpJsonFormatContext(s);
50+
BpXXXJsonFormatMyMessage((void *)m, &ctx);
51+
return ctx.n;
52+
}
53+
54+
void BpFieldDescriptorsInitMyPayload(struct MyPayload *m, struct BpMessageFieldDescriptor *fds) {
55+
}
56+
57+
void BpXXXProcessMyPayload(void *data, struct BpProcessorContext *ctx) {
58+
struct MyPayload *m = (struct MyPayload *)(data);
59+
struct BpMessageFieldDescriptor field_descriptors[0];
60+
BpFieldDescriptorsInitMyPayload(m, field_descriptors);
61+
struct BpMessageDescriptor descriptor = BpMessageDescriptor(false, 0, 0, field_descriptors);
62+
BpEndecodeMessage(&descriptor, ctx, data);
63+
}
64+
65+
void BpXXXJsonFormatMyPayload(void *data, struct BpJsonFormatContext *ctx) {
66+
struct MyPayload *m = (struct MyPayload *)(data);
67+
struct BpMessageFieldDescriptor field_descriptors[0];
68+
BpFieldDescriptorsInitMyPayload(m, field_descriptors);
69+
struct BpMessageDescriptor descriptor = BpMessageDescriptor(false, 0, 0, field_descriptors);
70+
BpJsonFormatMessage(&descriptor, ctx, data);
71+
}
72+
73+
int EncodeMyPayload(struct MyPayload *m, unsigned char *s) {
74+
struct BpProcessorContext ctx = BpProcessorContext(true, s);
75+
BpXXXProcessMyPayload((void *)m, &ctx);
76+
return 0;
77+
}
78+
79+
int DecodeMyPayload(struct MyPayload *m, unsigned char *s) {
80+
struct BpProcessorContext ctx = BpProcessorContext(false, s);
81+
BpXXXProcessMyPayload((void *)m, &ctx);
82+
return 0;
83+
}
84+
85+
int JsonMyPayload(struct MyPayload *m, char *s) {
86+
struct BpJsonFormatContext ctx = BpJsonFormatContext(s);
87+
BpXXXJsonFormatMyPayload((void *)m, &ctx);
88+
return ctx.n;
89+
}
90+
91+
void BpFieldDescriptorsInitMyOtherPayload(struct MyOtherPayload *m, struct BpMessageFieldDescriptor *fds) {
92+
}
93+
94+
void BpXXXProcessMyOtherPayload(void *data, struct BpProcessorContext *ctx) {
95+
struct MyOtherPayload *m = (struct MyOtherPayload *)(data);
96+
struct BpMessageFieldDescriptor field_descriptors[0];
97+
BpFieldDescriptorsInitMyOtherPayload(m, field_descriptors);
98+
struct BpMessageDescriptor descriptor = BpMessageDescriptor(false, 0, 0, field_descriptors);
99+
BpEndecodeMessage(&descriptor, ctx, data);
100+
}
101+
102+
void BpXXXJsonFormatMyOtherPayload(void *data, struct BpJsonFormatContext *ctx) {
103+
struct MyOtherPayload *m = (struct MyOtherPayload *)(data);
104+
struct BpMessageFieldDescriptor field_descriptors[0];
105+
BpFieldDescriptorsInitMyOtherPayload(m, field_descriptors);
106+
struct BpMessageDescriptor descriptor = BpMessageDescriptor(false, 0, 0, field_descriptors);
107+
BpJsonFormatMessage(&descriptor, ctx, data);
108+
}
109+
110+
int EncodeMyOtherPayload(struct MyOtherPayload *m, unsigned char *s) {
111+
struct BpProcessorContext ctx = BpProcessorContext(true, s);
112+
BpXXXProcessMyOtherPayload((void *)m, &ctx);
113+
return 0;
114+
}
115+
116+
int DecodeMyOtherPayload(struct MyOtherPayload *m, unsigned char *s) {
117+
struct BpProcessorContext ctx = BpProcessorContext(false, s);
118+
BpXXXProcessMyOtherPayload((void *)m, &ctx);
119+
return 0;
120+
}
121+
122+
int JsonMyOtherPayload(struct MyOtherPayload *m, char *s) {
123+
struct BpJsonFormatContext ctx = BpJsonFormatContext(s);
124+
BpXXXJsonFormatMyOtherPayload((void *)m, &ctx);
125+
return ctx.n;
126+
}

0 commit comments

Comments
 (0)