Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
protobuf-c
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
protobuf-c
Commits
69626956
Unverified
Commit
69626956
authored
Mar 20, 2021
by
Ilya Lipnitskiy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
protoc-c: add option to customize base field name
Fixes #287
parent
baa860ff
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
5 deletions
+13
-5
protobuf-c/protobuf-c.proto
protobuf-c/protobuf-c.proto
+3
-0
protoc-c/c_message.cc
protoc-c/c_message.cc
+10
-5
No files found.
protobuf-c/protobuf-c.proto
View file @
69626956
...
...
@@ -57,6 +57,9 @@ message ProtobufCMessageOptions {
// Overrides the parent setting only if present
optional
bool
gen_init_helpers
=
2
[
default
=
true
];
// Reserved base message field name
optional
string
base_field_name
=
3
[
default
=
"base"
];
}
extend
google
.
protobuf.MessageOptions
{
...
...
protoc-c/c_message.cc
View file @
69626956
...
...
@@ -178,10 +178,14 @@ GenerateStructDefinition(io::Printer* printer) {
descriptor_
->
GetSourceLocation
(
&
msgSourceLoc
);
PrintComment
(
printer
,
msgSourceLoc
.
leading_comments
);
const
ProtobufCMessageOptions
opt
=
descriptor_
->
options
().
GetExtension
(
pb_c_msg
);
vars
[
"base"
]
=
opt
.
base_field_name
();
printer
->
Print
(
vars
,
"struct $dllexport$ $classname$
\n
"
"{
\n
"
" ProtobufCMessage
base
;
\n
"
);
" ProtobufCMessage
$base$
;
\n
"
);
// Generate fields.
printer
->
Indent
();
...
...
@@ -367,6 +371,7 @@ GenerateHelperFunctionDefinitions(io::Printer* printer,
vars
[
"classname"
]
=
FullNameToC
(
descriptor_
->
full_name
());
vars
[
"lcclassname"
]
=
FullNameToLower
(
descriptor_
->
full_name
());
vars
[
"ucclassname"
]
=
FullNameToUpper
(
descriptor_
->
full_name
());
vars
[
"base"
]
=
opt
.
base_field_name
();
if
(
gen_init
)
{
printer
->
Print
(
vars
,
"void $lcclassname$__init
\n
"
...
...
@@ -381,21 +386,21 @@ GenerateHelperFunctionDefinitions(io::Printer* printer,
"size_t $lcclassname$__get_packed_size
\n
"
" (const $classname$ *message)
\n
"
"{
\n
"
" assert(message->
base
.descriptor == &$lcclassname$__descriptor);
\n
"
" assert(message->
$base$
.descriptor == &$lcclassname$__descriptor);
\n
"
" return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
\n
"
"}
\n
"
"size_t $lcclassname$__pack
\n
"
" (const $classname$ *message,
\n
"
" uint8_t *out)
\n
"
"{
\n
"
" assert(message->
base
.descriptor == &$lcclassname$__descriptor);
\n
"
" assert(message->
$base$
.descriptor == &$lcclassname$__descriptor);
\n
"
" return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
\n
"
"}
\n
"
"size_t $lcclassname$__pack_to_buffer
\n
"
" (const $classname$ *message,
\n
"
" ProtobufCBuffer *buffer)
\n
"
"{
\n
"
" assert(message->
base
.descriptor == &$lcclassname$__descriptor);
\n
"
" assert(message->
$base$
.descriptor == &$lcclassname$__descriptor);
\n
"
" return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
\n
"
"}
\n
"
"$classname$ *
\n
"
...
...
@@ -414,7 +419,7 @@ GenerateHelperFunctionDefinitions(io::Printer* printer,
"{
\n
"
" if(!message)
\n
"
" return;
\n
"
" assert(message->
base
.descriptor == &$lcclassname$__descriptor);
\n
"
" assert(message->
$base$
.descriptor == &$lcclassname$__descriptor);
\n
"
" protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
\n
"
"}
\n
"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment