22 Commits

Author SHA1 Message Date
Ilya Lipnitskiy
7df109917a
protoc-c: add c_package option
This option allows to override the top-level 'package' setting, or even
remove the package prefix altogether (if set to "").

Fixes #322
2021-03-21 21:11:51 -07:00
Ilya Lipnitskiy
4f39ca6e0c
protoc-c: don't use FullName helpers for non-full names
FullName* methods are designed to split a full name based on '.' in the
name. name() does not have '.' separators, so call CamelToLower and
CamelToUpper in place of FullNameToLower and FullNameToUpper.
2021-03-21 21:11:50 -07:00
Ilya Lipnitskiy
f486c8ed66
protoc-c: add use_oneof_field_name option
Allows for generic oneof offset lookups based on the name of the oneof,
instead of having to know the field name. All oneof fields should have
the same offset, since they are members of a union.

Fixes #204
2021-03-21 21:11:50 -07:00
Ilya Lipnitskiy
cebe3d03f9
protoc-c: add string as bytes option
Allows treating proto strings as ProtobufCBinaryData to work around
limitations such as NULL characters in strings, which are allowed in
protobuf, but not allowed in 'char *' types.

Fixes #203
2021-03-21 21:11:50 -07:00
Ilya Lipnitskiy
0e060260f0
protoc-c: add custom options support 2021-03-21 20:28:33 -07:00
Adam Cozzette
3d2ed0d410 Updated the generator to fully qualify std::string
The protobuf common.h header currently has a "using std::string;"
statement that pulls std::string into the google::protobuf namespace:
ce66f6047d/src/google/protobuf/stubs/common.h (L195)

I plan to delete that line soon. To keep protobuf-c working, this commit
updates the generator to fully qualify std::string.
2020-10-16 16:45:21 -07:00
Ilya Lipnitskiy
69c39824cf protoc-c/c_field.cc: Fix proto3 field packing #330
Fixes #330 and makes scalar repeated fields packed by default in proto3.

https://developers.google.com/protocol-buffers/docs/encoding#packed:
In proto3, repeated fields of scalar numeric types are packed by
default.
2019-05-17 13:29:06 -07:00
Robert Edmonds
83c59e705f Convert uses of protobuf's scoped_ptr.h to C++11 std::unique_ptr
Upstream protobuf removed scoped_ptr.h, which provided the scoped_ptr
that we depended on, in commit 67952fab2c766ac5eacc15bb78e5af4039a3d398
(67952fab2c).

This commit converts uses of scoped_ptr type to idiomatic C++11
std::unique_ptr, similar to the changes in the protobuf commit.

This has been tested on protobuf 3.0.0 (the version currently in Debian)
as well as the latest protobuf 3.6.1 release.
2018-08-13 21:26:00 -04:00
Robert Edmonds
582cad8bff Fix namespace errors when compiled with latest protobuf
The protobuf project removed "using namespace std" namespace pollution
from their stubs/common.h header file. This caused build failures for us
since we relied on their namespace pollution.

This commit updates protobuf-c to convert:

 'map' → 'std::map'
 'set' → 'std::set'
 'back_insert_iterator' → 'std::back_insert_iterator'
2017-07-29 18:52:28 -04:00
Paolo Borelli
2a46af4278 proto3: make strings default to "" instead of NULL
The spec talks about "empty string" and other languages like C#
return a zero length string and not null.
This is useful because when moving from proto2's "required string"
to a proto3's plain string we will be guaranteed that we
never get a null pointer.
The tradeoff is adding a special case to the library but avoiding
a lot of null checks in the calling code.
The current code is already special casing "" in pack_string.
2017-06-12 09:32:39 +02:00
Paolo Borelli
8194f4d91a proto3 support
This is a first cut at adding proto3 support.

As far as I understand protobuf-c already has pretty much everything
needed once it is built using a new version of protobuf itself.
The only missing thing is that in proto3 all fields are optional and
having to manually set has_foo is inconvenient.

This patch special cases the proto3 syntax files so that structs for the
bytes, enum and primitive fields do not emit the has_ field.

It also adds PROTOBUF_C_LABEL_NONE to the label enum that is used for
proto3 fields. When a fields has this label, the quantifier is not
consulted and instead the field is packed/unpacked depending on
whether it has a value different from NULL/0.
2016-10-30 10:06:52 +01:00
Ilya Lipnitskiy
0e2d3c09e2 Rename LITE_RUNTIME to CODE_SIZE 2015-10-30 15:54:00 -07:00
Ilya Lipnitskiy
603e431864 protoc-c: Support the optimize_for = LITE_RUNTIME file option
Adds support for the LITE_RUNTIME optimization option to the protobuf-c
compiler. Enabling this option would generate lighter weight message,
enum, and service descriptors that contain NO strings. As a result,
calls to lookup descriptors via the *_get_{field,value,method}_by_name
API will return NULL.

Default compiler behavior (when optimize_for is not specified or is not
set to LITE_RUNTIME) is unchanged.
2015-03-15 20:01:03 -07:00
Ilya Lipnitskiy
9db84a3b90 protoc-c: Implement oneofs 2014-11-19 23:07:23 -08:00
Robert Edmonds
c96fee16c2 PROTOBUF_C_OFFSETOF -> offsetof
offsetof() conforms to the C89 standard, just call it directly.
2014-06-04 17:28:51 -04:00
Andrei Nigmatulin
e962705437 added deprecated flag into ProtobufCFieldDescriptor->flags
[edmonds@fsi.io: resolve merge conflicts, add documentation]
2014-04-03 11:41:13 -04:00
Robert Edmonds
8a71fdab60 minor adjustments to the field flags patch
rename PROTOBUF_C_FIELD_FLAGS_PACKED to PROTOBUF_C_FIELD_FLAG_PACKED.

rename ProtobufCFieldFlagType to ProtobufCFieldFlag.

wrap some particular long lines.

update documentation.

for clarity, use a "uint32_t" instead of "unsigned" for the 'flags'
field in _ProtobufCFieldDescriptor.
2014-04-03 10:17:14 -04:00
Andrei Nigmatulin
9c6f2fe4d3 turned ProtobufCFieldDescriptor->packed into ->flags 2014-04-03 09:56:03 -04:00
Ilya Lipnitskiy
b915eed32f protobuf-c/protobuf-c.c: fix compiler warnings (fixes #115)
protoc-c/c_enum.cc: fix compiler warnings
protoc-c/c_field.cc: fix compiler warnings
2013-12-17 00:08:42 -08:00
Robert Edmonds
23c9b03ea7 update copyright and license statements throughout
per https://code.google.com/p/protobuf/source/detail?r=50, the license
on google-originated protobuf code was switched from Apache-2.0 to
BSD-3-Clause (so-called "New BSD" license). update any of the google
license statements to use this new license.

per email with dave, drop the third clause on his BSD-3-Clause license,
so this now becomes BSD-2-Clause.

make sure to use consistent indentation and wrapping throughout.
2013-11-18 20:25:34 -05:00
Robert Edmonds
653c04ea2c protoc-c/: fix include paths 2013-11-16 17:11:48 -05:00
Robert Edmonds
bbed775dae compiler/ -> protoc-c/ 2013-11-16 15:48:12 -05:00