mirror of
https://github.com/protobuf-c/protobuf-c.git
synced 2024-12-27 13:31:02 +08:00
Merge pull request #377 from protobuf-c/ilya/issue330
Fix proto3 repeated scalar field default packing behavior (#330)
This commit is contained in:
commit
c404ce3eb0
17
Makefile.am
17
Makefile.am
@ -250,6 +250,23 @@ BUILT_SOURCES += \
|
||||
EXTRA_DIST += \
|
||||
t/issue251/issue251.proto
|
||||
|
||||
# Issue #330
|
||||
check_PROGRAMS += \
|
||||
t/issue330/issue330
|
||||
TESTS += \
|
||||
t/issue330/issue330
|
||||
t_issue330_issue330_SOURCES = \
|
||||
t/issue330/issue330.c \
|
||||
t/issue330/issue330.pb-c.c
|
||||
t_issue330_issue330_LDADD = \
|
||||
protobuf-c/libprotobuf-c.la
|
||||
t/issue330/issue330.pb-c.c t/issue330/issue330.pb-c.h: $(top_builddir)/protoc-c/protoc-gen-c$(EXEEXT) $(top_srcdir)/t/issue330/issue330.proto
|
||||
$(AM_V_GEN)@PROTOC@ --plugin=protoc-gen-c=$(top_builddir)/protoc-c/protoc-gen-c$(EXEEXT) -I$(top_srcdir) --c_out=$(top_builddir) $(top_srcdir)/t/issue330/issue330.proto
|
||||
BUILT_SOURCES += \
|
||||
t/issue330/issue330.pb-c.c t/issue330/issue330.pb-c.h
|
||||
EXTRA_DIST += \
|
||||
t/issue330/issue330.proto
|
||||
|
||||
# Issue #375
|
||||
check_PROGRAMS += \
|
||||
t/issue375/issue375
|
||||
|
@ -140,8 +140,14 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer,
|
||||
|
||||
if (descriptor_->label() == FieldDescriptor::LABEL_REPEATED
|
||||
&& is_packable_type (descriptor_->type())
|
||||
&& descriptor_->options().packed())
|
||||
&& descriptor_->options().packed()) {
|
||||
variables["flags"] += " | PROTOBUF_C_FIELD_FLAG_PACKED";
|
||||
} else if (descriptor_->label() == FieldDescriptor::LABEL_REPEATED
|
||||
&& is_packable_type (descriptor_->type())
|
||||
&& FieldSyntax(descriptor_) == 3
|
||||
&& !descriptor_->options().has_packed()) {
|
||||
variables["flags"] += " | PROTOBUF_C_FIELD_FLAG_PACKED";
|
||||
}
|
||||
|
||||
if (descriptor_->options().deprecated())
|
||||
variables["flags"] += " | PROTOBUF_C_FIELD_FLAG_DEPRECATED";
|
||||
|
1
t/issue330/.gitignore
vendored
Normal file
1
t/issue330/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
issue330
|
25
t/issue330/issue330.c
Normal file
25
t/issue330/issue330.c
Normal file
@ -0,0 +1,25 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "t/issue330/issue330.pb-c.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/* Output of $ echo acl_id: 2 acl_id: 3 | protoc issue330.proto \
|
||||
* --encode=pbr_route | xxd -i: 0x52, 0x02, 0x02, 0x03
|
||||
*/
|
||||
uint8_t protoc[] = {0x52, 0x02, 0x02, 0x03};
|
||||
PbrRoute msg = PBR_ROUTE__INIT;
|
||||
int ids[] = {2, 3};
|
||||
uint8_t buf[16] = {0};
|
||||
size_t sz = 0;
|
||||
|
||||
msg.n_acl_id = 2;
|
||||
msg.acl_id = ids;
|
||||
sz = pbr_route__pack(&msg, buf);
|
||||
|
||||
assert (sz == sizeof protoc);
|
||||
assert (memcmp (protoc, buf, sz) == 0);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
5
t/issue330/issue330.proto
Normal file
5
t/issue330/issue330.proto
Normal file
@ -0,0 +1,5 @@
|
||||
syntax = "proto3";
|
||||
|
||||
message pbr_route {
|
||||
repeated int32 acl_id = 10;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user