Git Product home page Git Product logo

protobuf-d's People

Contributors

dcarp avatar denizzzka avatar deviator avatar vnayar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

protobuf-d's Issues

Wrong handling of repeated packed scalar fields

Repeated packed scalar fields like this:

repeated sint64 id = 1 [packed = true];

Readed with error:
google.protobuf.common.ProtobufException@../protobuf-d/src/google/protobuf/decoding.d(188): Wrong wire format 'withLength' of field DenseNodes.id, expected 'varint'

This field must be threated as wire format 'withLength':
https://developers.google.com/protocol-buffers/docs/encoding

Packed Repeated Fields
Version 2.1.0 introduced packed repeated fields, which in proto2 are declared like repeated fields but with the special [packed=true] option. In proto3, repeated fields of scalar numeric types are packed by default. These function like repeated fields, but are encoded differently. A packed repeated field containing zero elements does not appear in the encoded message. Otherwise, all of the elements of the field are packed into a single key-value pair with wire type 2 (length-delimited). Each element is encoded the same way it would be normally, except without a key preceding it.

Optional fields

Generator told me:

xxx.proto: is a proto3 file that contains optional fields, but code generator protoc-gen-d hasn't been updated to support optional fields in proto3. Please ask the owner of this code generator to support proto3 optional.--d_out:

So, I ask you :-) Please :-)

With best regards
Radek

AssertError

Facing the below error when trying to generate bindings with the master.

core.exception.AssertError@src/google/protobuf/internal.d(47): Assertion failure
----------------
??:? _d_assertp [0x4e3df0]
src/google/protobuf/internal.d:47 const ubyte google.protobuf.internal.Varint.opIndex(ulong) [0x4d9cdf]
src/google/protobuf/internal.d:43 const @property ubyte google.protobuf.internal.Varint.front() [0x4d9c8e]
/home/prabhu/dlang/dmd-2.106.0/linux/bin64/../../src/phobos/std/range/package.d:1094 @property ubyte std.range.chain!(google.protobuf.internal.Varint, std.range.chain!(google.protobuf.internal.Varint, ubyte[]).chain(google.protobuf.internal.Varint, ubyte[]).Result).chain(google.protobuf.internal.Varint, std.range.chain!(google.protobuf.internal.Varint, ubyte[]).chain(google.protobuf.internal.Varint, ubyte[]).Result).Result.front() [0x4bbfc7]
/home/prabhu/dlang/dmd-2.106.0/linux/bin64/../../src/phobos/std/range/package.d:1094 @property ubyte std.range.chain!(std.range.chain!(google.protobuf.internal.Varint, std.range.chain!(google.protobuf.internal.Varint, ubyte[]).chain(google.protobuf.internal.Varint, ubyte[]).Result).chain(google.protobuf.internal.Varint, std.range.chain!(google.protobuf.internal.Varint, ubyte[]).chain(google.protobuf.internal.Varint, ubyte[]).Result).Result, google.protobuf.internal.sizedJoiner!(std.algorithm.iteration.MapResult!(google.protobuf.encoding.toProtobufByProto!(google.protobuf.common.Proto(15, 0, 0), google.protobuf.compiler.plugin.CodeGeneratorResponse.File[]).toProtobufByProto(google.protobuf.compiler.plugin.CodeGeneratorResponse.File[]).__lambda3, google.protobuf.compiler.plugin.CodeGeneratorResponse.File[]).MapResult).sizedJoiner(std.algorithm.iteration.MapResult!(google.protobuf.encoding.toProtobufByProto!(google.protobuf.common.Proto(15, 0, 0), google.protobuf.compiler.plugin.CodeGeneratorResponse.File[]).toProtobufByProto(google.protobuf.compiler.plugin.CodeGeneratorResponse.File[]).__lambda3, google.protobuf.compiler.plugin.CodeGeneratorResponse.File[]).MapResult).Result).chain(std.range.chain!(google.protobuf.internal.Varint, std.range.chain!(google.protobuf.internal.Varint, ubyte[]).chain(google.protobuf.internal.Varint, ubyte[]).Result).chain(google.protobuf.internal.Varint, std.range.chain!(google.protobuf.internal.Varint, ubyte[]).chain(google.protobuf.internal.Varint, ubyte[]).Result).Result, google....
/home/prabhu/dlang/dmd-2.106.0/linux/bin64/../../src/phobos/std/array.d:132 ubyte[] std.array.array!(std.range.chain!(std.range.chain!(google.protobuf.internal.Varint, std.range.chain!(google.protobuf.internal.Varint, ubyte[]).chain(google.protobuf.internal.Varint, ubyte[]).Result).chain(google.protobuf.internal.Varint, std.range.chain!(google.protobuf.internal.Varint, ubyte[]).chain(google.protobuf.internal.Varint, ubyte[]).Result).Result, google.protobuf.internal.sizedJoiner!(std.algorithm.iteration.MapResult!(google.protobuf.encoding.toProtobufByProto!(google.protobuf.common.Proto(15, 0, 0), google.protobuf.compiler.plugin.CodeGeneratorResponse.File[]).toProtobufByProto(google.protobuf.compiler.plugin.CodeGeneratorResponse.File[]).__lambda3, google.protobuf.compiler.plugin.CodeGeneratorResponse.File[]).MapResult).sizedJoiner(std.algorithm.iteration.MapResult!(google.protobuf.encoding.toProtobufByProto!(google.protobuf.common.Proto(15, 0, 0), google.protobuf.compiler.plugin.CodeGeneratorResponse.File[]).toProtobufByProto(google.protobuf.compiler.plugin.CodeGeneratorResponse.File[]).__lambda3, google.protobuf.compiler.plugin.CodeGeneratorResponse.File[]).MapResult).Result).chain(std.range.chain!(google.protobuf.internal.Varint, std.range.chain!(google.protobuf.internal.Varint, ubyte[]).chain(google.protobuf.internal.Varint, ubyte[]).Result).chain(google.protobuf.internal.Varint, std.range.chain!(google.protobuf.internal.Varint, ubyte[]).chain(google.protobuf.internal.Varint, ubyte[]).Result).Result, google....
protoc_gen_d/protoc-gen-d.d:20 _Dmain [0x4d274f]
--d_out: protoc-gen-d: Plugin failed with status code 1.

Proto file: https://github.com/AppThreat/atom/blob/main/specification/atom.proto

protoc -I . --d_out=bindings/d atom.proto

Fails to build with LDC on Linux

dub build :protoc-gen-d
Building package protobuf:protoc-gen-d in /home/deviator/tests/dtest/usbdev/protobuf-d/protoc_gen_d/
Performing "debug" build using /opt/ldc2/bin/ldc2 for x86_64.
protobuf ~master: building configuration "protobuf"...
Invalid bitcast
%std.datetime.timezone.TimeZone* bitcast (/opt/ldc2/bin/ldc2(_ZN4llvm3sys15PrintStackTraceERNS_11raw_ostreamE+0x1a)[0x2a600da]
/opt/ldc2/bin/ldc2(_ZN4llvm3sys17RunSignalHandlersEv+0x35)[0x2a5e7d5]
/opt/ldc2/bin/ldc2[0x2a5e8ec]
/lib64/libpthread.so.0(+0x11fb0)[0x7f7db1c70fb0]
/opt/ldc2/bin/ldc2(_ZTV8DImValue+0x10)[0x3c8e748]
/opt/ldc2/bin/ldc2 failed with exit code -11.

protobuf-d: 0.4.1 from github releases
OS: Fedora 28 4.19.13-200
ldc: 1.13.0 from github releases (on 1.12.0 too)
dub: 1.12.1

I know it can be ldc issue, but no more code break ldc at last time in my work, only protobuf-d. May be it can be easy fixed without change functionality?

Error: Tag value out of range

class ApplyContact
{
    @Proto(1) string fromId = protoDefaultValue!string;
    @Proto(2) string toId = protoDefaultValue!string;
    @Proto(3) string message = protoDefaultValue!string;
    @Proto(4) string chatId = protoDefaultValue!string;
    @Proto(5) ulong timestamp = protoDefaultValue!ulong;
    @Proto(6) ContactApplySrc src = protoDefaultValue!ContactApplySrc;
    @Proto(7) uint tagId = protoDefaultValue!uint;
}
2023-Oct-16 19:28:51.7708915 | 2772099 | warning | execute | google.protobuf.common.ProtobufException@/root/.dub/packages/protobuf-0.6.2/protobuf/src/google/protobuf/internal.d(199): Tag value out of range
----------------
/usr/include/dmd/phobos/std/exception.d:515 pure @safe void std.exception.bailOut!(google.protobuf.common.ProtobufException).bailOut(immutable(char)[], ulong, scope const(char)[]) [0x56522c393626]
/usr/include/dmd/phobos/std/exception.d:436 pure @safe bool std.exception.enforce!(google.protobuf.common.ProtobufException).enforce!(bool).enforce(bool, lazy const(char)[], immutable(char)[], ulong) [0x56522c3935a2]
/root/.dub/packages/protobuf-0.6.2/protobuf/src/google/protobuf/internal.d:199 pure @safe std.typecons.Tuple!(uint, "tag", google.protobuf.internal.WireType, "wireType").Tuple google.protobuf.internal.decodeTag!(ubyte[]).decodeTag(ref ubyte[]) [0x56522c5296ec]
/root/.dub/packages/protobuf-0.6.2/protobuf/src/google/protobuf/decoding.d:192 pure privchat.protocol.contacts.ApplyContact google.protobuf.decoding.fromProtobuf!(privchat.protocol.contacts.ApplyContact, ubyte[]).fromProtobuf(ref ubyte[], privchat.protocol.contacts.ApplyContact) [0x56522c535c58]
source/executor/friend/ApplyFriendExecutor.d:23 void executor.friend.ApplyContactExecutor.ApplyContactExecutor.applyFriend(msgtrans.TransportContext.TransportContext, msgtrans.MessageBuffer.MessageBuffer) [0x56522c5cfdef]
/root/.dub/packages/hunt-reflection-0.2.1/hunt-reflection/source/witchcraft/mixins/methods.d:160 const std.variant.VariantN!(32uL).VariantN msgtrans.executor.AbstractExecutor.AbstractExecutor!(executor.friend.ApplyContactExecutor.ApplyContactExecutor).AbstractExecutor.__mixin3.__mixin8.MethodMixin!(executor.friend.ApplyContactExecutor.ApplyContactExecutor, "applyFriend", 0uL).MethodMixin.invoke(std.variant.VariantN!(32uL).VariantN, std.variant.VariantN!(32uL).VariantN[]...) [0x56522c5a6d18]
/root/.dub/packages/hunt-reflection-0.2.1/hunt-reflection/source/witchcraft/invocable.d:90 const std.variant.VariantN!(32uL).VariantN witchcraft.invocable.Invocable.invoke!(std.variant.VariantN!(32uL).VariantN, Object, msgtrans.TransportContext.TransportContext, msgtrans.MessageBuffer.MessageBuffer).invoke(Object, msgtrans.TransportContext.TransportContext, msgtrans.MessageBuffer.MessageBuffer) [0x56522d025a35]
/root/.dub/packages/msgtrans-0.1.4/msgtrans/source/msgtrans/executor/ExecutorInfo.d:73 nothrow void msgtrans.executor.ExecutorInfo.ExecutorInfo.execute!().execute(ref msgtrans.TransportContext.TransportContext, msgtrans.MessageBuffer.MessageBuffer) [0x56522d02566f]
/root/.dub/packages/msgtrans-0.1.4/msgtrans/source/msgtrans/channel/tcp/TcpServerChannel.d:217 void msgtrans.channel.tcp.TcpServerChannel.TcpServerChannel.dispatchMessage(hunt.net.Connection.Connection, msgtrans.MessageBuffer.MessageBuffer) [0x56522d0208b6]
/root/.dub/packages/msgtrans-0.1.4/msgtrans/source/msgtrans/channel/tcp/TcpServerChannel.d:150 hunt.io.channel.Common.DataHandleStatus msgtrans.channel.tcp.TcpServerChannel.TcpServerChannel.initialize().__anonclass4.messageReceived(hunt.net.Connection.Connection, Object) [0x56522d020550]
/root/.dub/packages/msgtrans-0.1.4/msgtrans/source/msgtrans/channel/tcp/TcpDecoder.d:112 hunt.io.channel.Common.DataHandleStatus msgtrans.channel.tcp.TcpDecoder.TcpDecoder.decode(hunt.io.ByteBuffer.ByteBuffer, hunt.net.Connection.Connection) [0x56522d035c61]
/root/.dub/packages/hunt-net-0.6.6/hunt-net/source/hunt/net/AbstractConnection.d:178 hunt.io.channel.Common.DataHandleStatus hunt.net.AbstractConnection.AbstractConnection.handleReceivedData(hunt.io.ByteBuffer.ByteBuffer) [0x56522d2776c0]
/root/.dub/packages/hunt-net-0.6.6/hunt-net/source/hunt/net/AbstractConnection.d:159 hunt.io.channel.Common.DataHandleStatus hunt.net.AbstractConnection.AbstractConnection.onDataReceived(hunt.io.ByteBuffer.ByteBuffer) [0x56522d2775eb]
/root/.dub/packages/hunt-1.7.13/hunt/source/hunt/io/channel/posix/AbstractStream.d:83 void hunt.io.channel.posix.AbstractStream.AbstractStream.onDataReceived(hunt.io.ByteBuffer.ByteBuffer) [0x56522d3a362c]
/root/.dub/packages/hunt-1.7.13/hunt/source/hunt/io/channel/posix/AbstractStream.d:142 bool hunt.io.channel.posix.AbstractStream.AbstractStream.tryRead() [0x56522d3a37ab]
/root/.dub/packages/hunt-1.7.13/hunt/source/hunt/io/TcpStream.d:428 void hunt.io.TcpStream.TcpStream.onRead() [0x56522d3a23a0]
/root/.dub/packages/hunt-1.7.13/hunt/source/hunt/event/selector/Epoll.d:228 void hunt.event.selector.Epoll.AbstractSelector.handeChannelEvent(hunt.io.channel.AbstractChannel.AbstractChannel, uint) [0x56522d39adcb]
/root/.dub/packages/hunt-1.7.13/hunt/source/hunt/event/selector/Epoll.d:173 int hunt.event.selector.Epoll.AbstractSelector.doSelect(long) [0x56522d39ad14]
/root/.dub/packages/hunt-1.7.13/hunt/source/hunt/event/selector/Selector.d:195 void hunt.event.selector.Selector.Selector.onLoop(long) [0x56522d39b66a]
/root/.dub/packages/hunt-1.7.13/hunt/source/hunt/event/selector/Selector.d:155 void hunt.event.selector.Selector.Selector.doRun(void delegate()) [0x56522d39b574]
/root/.dub/packages/hunt-1.7.13/hunt/source/hunt/event/selector/Selector.d:120 nothrow void hunt.event.selector.Selector.Selector.runAsync(long, void delegate()).__lambda3() [0x56522d39b4a7]
??:? void core.thread.Thread.run() [0x56522d3e80f9]
??:? thread_entryPoint [0x56522d43017b]
??:? [0x7fda50287ea6] | /root/.dub/packages/msgtrans-0.1.4/msgtrans/source/msgtrans/executor/ExecutorInfo.d:75

built-in types are structs instead of classes

built-in/google types are generated as structs, which seem to be causing a lot of issues with template instantiation. replacing struct with class fixes most compilation issues for me

Fails to build with LDC on Windows

LDC2: 1.11.0 (DMD v2.081.2, LLVM 6.0.1)
OS: Windows 10 x64

Build command:

dub build  --arch=x86_64 --build=debug --compiler=ldc2

Error:

protobuf 0.3.1+commit.3.g35a9281: building configuration "protobuf"...
Invalid bitcast
%std.datetime.timezone.TimeZone* bitcast (Wrote crash dump file "d:\temp\ldc2.exe-91fe99.dmp"
0x00007FF84FD4C88B (0x000000F0F2B1E878 0x0000000000000000 0x00007FF7E0536990 0x0000000000000002) <unknown module>
0x000055C103FEE57D (0x0000000000000000 0x00007FF7E0536990 0x0000000000000002 0x00007FF7DF373AE4) <unknown module>
0x000000F0F2B1E878 (0x00007FF7E0536990 0x0000000000000002 0x00007FF7DF373AE4 0x0000000000000001) <unknown module>
ldc2 failed with exit code -1073741819.

Add support for proto2

proto2 is still quite common, so we should consider supporting it. E.g. the proto files I deal with at work are all proto2 files.

gdc 11 not compiling: error: module std.json import ‘JSONType’ not found

Debian unstable, wit

libgphobos-11-dev:amd64                                     11.2.0-20
gdc-11                                                      11.2.0-20

master @ 655197e

user@debian:~/pb/protobuf-d$ dub build :protoc-gen-d
Performing "debug" build using /usr/bin/gdc for x86_64.
protobuf 0.6.2+commit.3.g655197e: building configuration "protobuf"...
src/google/protobuf/json_decoding.d:3:8: error: module std.json import ‘JSONType’ not found
    3 | import std.json : JSONValue, JSONType;
      |        ^
/usr/bin/gdc failed with exit code 1.

gdc-12 with libgphobos-12-dev 12-20220319-1 from Debian unstable seems to work tho:

user@debian:~/pb/protobuf-d$ DC=gdc-12 dub build :protoc-gen-d
Performing "debug" build using /usr/bin/gdc-12 for x86_64.
protobuf 0.6.2+commit.3.g655197e: building configuration "protobuf"...

So I guess gdc-11 has a bit old Phobos included.

It would be nice to have gdc included in CI tho to catch these things automatically.

Example segfaults on Ubuntu 18.04.1

Steps to reproduce:

git clone https://github.com/dcarp/protobuf-d.git master
cd master
dub build :protoc-gen-d
cd examples
dub build :add_person

Here's the output of that last command:

Building package examples:add_person in /home/cconvey/r/dcarp/protbuf-d/master/examples/
Invalid source/import path: /home/cconvey/r/dcarp/protbuf-d/master/examples/tutorial
Performing "debug" build using /usr/bin/dmd for x86_64.
examples:add_person ~master: building configuration "application"...
Running pre-build commands...
--d_out: protoc-gen-d: Plugin killed by signal 11.
Command failed with exit code 1: protoc --plugin=../build/protoc-gen-d --d_out=. addressbook.proto

Some potentially relevant software versions:

cconvey@cconvey-u1804 ~/r/dcarp/protbuf-d/master/examples $ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.1 LTS
Release:	18.04
Codename:	bionic

cconvey@cconvey-u1804 ~/r/dcarp/protbuf-d/master/examples $ dmd --version
DMD64 D Compiler v2.081.1
Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved written by Walter Bright

cconvey@cconvey-u1804 ~/r/dcarp/protbuf-d/master/examples $ dub --version
DUB version 1.10.0, built on Jul 10 2018

cconvey@cconvey-u1804 ~/r/dcarp/protbuf-d/master/examples $ protoc --version
libprotoc 3.0.0

Error: template google.protobuf.internal.takeN cannot deduce function from argument types !()(ubyte[], long), candidates

$ dub
Fetching hunt 1.1.0 (getting selected version)...
Fetching hunt-net 0.1.0 (getting selected version)...
Fetching protobuf 0.4.0 (getting selected version)...
Fetching hunt-security 0.1.0 (getting selected version)...
Fetching hunt-imf 0.0.5 (getting selected version)...
Fetching hunt-trace 0.1.8 (getting selected version)...
Fetching boringssl 0.0.1 (getting selected version)...
Performing "debug" build using C:\D\dmd2\windows\bin\dmd.exe for x86.
hunt 1.1.0: building configuration "library"...
hunt-security 0.1.0: building configuration "library"...
hunt-net 0.1.0: building configuration "default"...
protobuf 0.4.0: building configuration "protobuf"...
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\internal.d(473,28): Error: template google.protobuf.internal.takeN cannot deduce function from argument types !()(ubyte[], long), candidates are:
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\internal.d(476,3):        google.protobuf.internal.takeN(R)(ref R inputRange, size_t size)
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\decoding.d(107,30): Error: template instance `google.protobuf.internal.takeLengthPrefixed!(ubyte[])` error instantiating
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\decoding.d(256,23):        instantiated from here: fromProtobuf!(string, ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\decoding.d(240,30):        instantiated from here: fromProtobufByProto!(Proto(1u, cast(Wire)cast(ubyte)0u, cast(Flag)false), string, ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\decoding.d(191,77):        instantiated from here: fromProtobufByField!(typeUrl, _Message, ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\any.d(92,34):        ... (2 instantiations, -v to show) ...
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\any.d(170,72):        instantiated from here: fromProtobuf!(Any, ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\any.d(193,8):        instantiated from here: registerMessageType!(Any, cast(Flag)true)
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\decoding.d(256,23): Error: template instance `google.protobuf.decoding.fromProtobuf!(ubyte[], ubyte[])` error instantiating
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\decoding.d(240,30):        instantiated from here: fromProtobufByProto!(Proto(2u, cast(Wire)cast(ubyte)0u, cast(Flag)false), ubyte[], ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\decoding.d(191,77):        instantiated from here: fromProtobufByField!(value, _Message, ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\any.d(92,34):        instantiated from here: fromProtobuf!(_Message, ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\decoding.d(169,35):        ... (1 instantiations, -v to show) ...
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\any.d(170,72):        instantiated from here: fromProtobuf!(Any, ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\any.d(193,8):        instantiated from here: registerMessageType!(Any, cast(Flag)true)
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\decoding.d(196,28): Error: template instance `google.protobuf.decoding.skipUnknown!(ubyte[])` error instantiating
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\any.d(92,34):        instantiated from here: fromProtobuf!(_Message, ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\decoding.d(169,35):        instantiated from here: fromProtobuf!(ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\any.d(170,72):        instantiated from here: fromProtobuf!(Any, ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\any.d(193,8):        instantiated from here: registerMessageType!(Any, cast(Flag)true)
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\wrappers.d(34,27): Error: template instance `google.protobuf.decoding.fromProtobuf!(_Message, ubyte[])` error instantiating
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\decoding.d(169,35):        instantiated from here: fromProtobuf!(ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\any.d(170,72):        instantiated from here: fromProtobuf!(WrappedValue!(bool, "google.protobuf.BoolValue"), ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\any.d(194,8):        instantiated from here: registerMessageType!(WrappedValue!(bool, "google.protobuf.BoolValue"), cast(Flag)true)
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\decoding.d(240,30): Error: template instance `google.protobuf.decoding.fromProtobufByProto!(Proto(1u, cast(Wire)cast(ubyte)0u, cast(Flag)false), ubyte[], ubyte[])` error instantiating
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\decoding.d(191,77):        instantiated from here: fromProtobufByField!(value, _Message, ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\wrappers.d(34,27):        instantiated from here: fromProtobuf!(_Message, ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\decoding.d(169,35):        instantiated from here: fromProtobuf!(ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\any.d(170,72):        instantiated from here: fromProtobuf!(WrappedValue!(ubyte[], "google.protobuf.BytesValue"), ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\any.d(195,8):        instantiated from here: registerMessageType!(WrappedValue!(ubyte[], "google.protobuf.BytesValue"), cast(Flag)true)
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\wrappers.d(34,27): Error: template instance `google.protobuf.decoding.fromProtobuf!(_Message, ubyte[])` error instantiating
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\decoding.d(169,35):        instantiated from here: fromProtobuf!(ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\any.d(170,72):        instantiated from here: fromProtobuf!(WrappedValue!(double, "google.protobuf.DoubleValue"), ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\any.d(196,8):        instantiated from here: registerMessageType!(WrappedValue!(double, "google.protobuf.DoubleValue"), cast(Flag)true)
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\duration.d(37,34): Error: template instance `google.protobuf.decoding.fromProtobuf!(_Message, ubyte[])` error instantiating
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\decoding.d(169,35):        instantiated from here: fromProtobuf!(ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\any.d(170,72):        instantiated from here: fromProtobuf!(Duration, ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\any.d(197,8):        instantiated from here: registerMessageType!(Duration, cast(Flag)true)
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\decoding.d(240,30): Error: template instance `google.protobuf.decoding.fromProtobufByProto!(Proto(1u, cast(Wire)cast(ubyte)0u, cast(Flag)false), string[], ubyte[])` error instantiating
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\decoding.d(191,77):        instantiated from here: fromProtobufByField!(paths, FieldMask, ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\any.d(170,72):        instantiated from here: fromProtobuf!(FieldMask, ubyte[])
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\any.d(199,8):        instantiated from here: registerMessageType!(FieldMask, cast(Flag)true)
..\..\..\..\..\AppData\Local\dub\packages\protobuf-0.4.0\protobuf\src\google\protobuf\wrappers.d(34,27): Error: template instance `google.protobuf.decoding.fromProtobuf!(_Message, ubyte[])` error instantiating
C:\D\dmd2\windows\bin\dmd.exe failed with exit code 1.

Windows 10.
$ dmd
DMD32 D Compiler v2.084.0

empty message error.

protobuf-0.3.1/protobuf/src/google/protobuf/common.d(147,5): Error: static assert: "Definition of 'LeaseLeasesRequest' has no Proto field"

message LeaseLeasesRequest {
}

sometimes empty message is useful , for example used in grpc.

gdc-11 is not supported

One can't compile this project with gdc-11, probably because it targets an old version of D frontend.

For example cd src/google/protobuf/ then gdc-11 -c decoding.d -I ../.. -funittest gives this error (this is only the beginning of the trace) :

decoding.d:346:23: error: template google.protobuf.decoding.fromProtobuf cannot deduce function from argument types !(int, wire)(ubyte[]), candidates are:            
      346 |     field = inputRange.fromProtobuf!(T, proto.wire);                                                                                                          
          |                       ^                                                                                                                                       
    decoding.d:8:3: note: google.protobuf.decoding.fromProtobuf(T, R)(ref R inputRange) if (isInputRange!R && isBoolean!T)                                                
        8 | T fromProtobuf(T, R)(ref R inputRange)                                                                                                                        
          |   ^                                                                                                                                                           
    decoding.d:25:3: note: google.protobuf.decoding.fromProtobuf(T, Wire wire = Wire.none, R)(ref R inputRange) if (isInputRange!R && isIntegral!T)                       
       25 | T fromProtobuf(T, Wire wire = Wire.none, R)(ref R inputRange)                                                                                                 
          |   ^                                                                                                                                                           
   decoding.d:83:3: note: google.protobuf.decoding.fromProtobuf(T, R)(ref R inputRange) if (isInputRange!R && isFloatingPoint!T)                                         
      83 | T fromProtobuf(T, R)(ref R inputRange)                                                                                                                        
         |   ^                                                                                                                                                           
   decoding.d:100:3: note: google.protobuf.decoding.fromProtobuf(T, R)(ref R inputRange) if (isInputRange!R && (is(T == string) || is(T == bytes)))                      
     100 | T fromProtobuf(T, R)(ref R inputRange)                                                                                                                        
         |   ^                                                                                                                                                           
   decoding.d:127:3: note: google.protobuf.decoding.fromProtobuf(T, Wire wire = Wire.none, R)(ref R inputRange) if (isInputRange!R && isArray!T && !is(T == string) && !i
     127 | T fromProtobuf(T, Wire wire = Wire.none, R)(ref R inputRange)                                                                                                 
         |   ^                                                                                                                                                           
   decoding.d:346:23: note: ... (1 more, -v to show) ...                                                                                                                 
     346 |     field = inputRange.fromProtobuf!(T, proto.wire);                                                                                                          
         |                       ^                                                                                                                                    

Do you have any hint to make it compatible with gdc-11 ?

sint64 corrupt read from wire

While (third-party created) wire binary reading sint64 values treated as unsigned. This causes what zagZig is not applied to it and values readed wrong.

For example, sint64 value 54 will be readed as 108

integration tests testing something by wrong way?

Field:

repeated sint64 id = 1 [packed = true];
@Proto(1, Wire.zigzag, Yes.packed) long[] id = protoDefaultValue!(long[]);

Generating googleapis client libraries with protobuf-d

Hello!

I am currently working on "D Language Client Libraries for Google APIs" project[0][1].
The first step was to familiarize myself with protobuf and to generate client library for cloud/vision using python plugin with protoc.
Today I generated the same library with protobuf-d. When I tried to translate this example[2] from python to D, I noticed that some pieces of code are missing from the D generated library, for example the ImageAnnotatorClient class(or struct) (I could not found it anywhere in the generated code).

Here is the command that I used to generate the client library:

protoc path/to/cloud/vision/proto/files
--proto_path=path/to/common/api/protos --proto-path=.
--plugin=path/to/protobuf-d --d_opt=message-as-struct
--d_out=path/to/output/files

Is that ok? Does it work as it should?

Thanks!

[0] dlang/project-ideas#66
[1]https://forum.dlang.org/post/[email protected]
[2] https://gapic-generator-python.readthedocs.io/en/stable/getting-started/docker.html#verifying-the-library

Add support for optional fields

When trying to compile the protobuf files from Stability-AI I get the following error:

project.proto: is a proto3 file that contains optional fields, but code generator protoc-gen-d hasn't been updated to support optional fields in proto3. Please ask the owner of this code generator to support proto3 optional.

Is it possible to add support for optional fields?

Replace dash with underscore for generated D files?

One of the upstream dependencies I'm targeting uses a file named kafka-egress.proto, this generates a D file named kafka-egress.d with a module declaration module kafka-egress.d.

This won't compile in D as - is not valid in a module declaration.

I could rename the upstream file, but I'd rather not taint the sources.

Could protobuf-d be fixed to replace - with an underscore _ in both the generated filename and the module declaration?

Example's `dub :add_person` always fails first time

I start with a clean checkout of the master branch (currently commit 7b6fab), and try to perform the steps in this example.

When I run the command

dub build :add_person

its first invocation fails, but its second invocation succeeds.

I'm using the same software versions as described in #6 .

Here's the output from those steps:

cconvey@cconvey-u1804 ~/r/dcarp/protbuf-d/master $ dub build :protoc-gen-d
Building package protobuf:protoc-gen-d in /home/cconvey/r/dcarp/protbuf-d/master/protoc_gen_d/
Performing "debug" build using /usr/bin/dmd for x86_64.
protobuf 0.3.1: building configuration "protobuf"...
protobuf:protoc-gen-d 0.3.1: building configuration "application"...
Linking...
cconvey@cconvey-u1804 ~/r/dcarp/protbuf-d/master $ cd examples/
cconvey@cconvey-u1804 ~/r/dcarp/protbuf-d/master/examples $ dub build :add_person
Building package examples:add_person in /home/cconvey/r/dcarp/protbuf-d/master/examples/
Invalid source/import path: /home/cconvey/r/dcarp/protbuf-d/master/examples/tutorial
Performing "debug" build using /usr/bin/dmd for x86_64.
examples:add_person ~master: building configuration "application"...
Running pre-build commands...
Linking...
.dub/build/application-debug-linux.posix-x86_64-dmd_2081-35F3EDE3A35CB79A60ECFF64D8473489/add_person.o:(.data.rel.ro+0x260): undefined reference to `_D8tutorial11addressbook12__ModuleInfoZ'
.dub/build/application-debug-linux.posix-x86_64-dmd_2081-35F3EDE3A35CB79A60ECFF64D8473489/add_person.o: In function `_D3std5range10primitives__T9moveFrontTS6google8protobuf8internal__T11sizedJoinerTSQDc9algorithm9iteration__T9MapResultSQDcQCy8encoding__T17toProtobufByProtoVSQEpQEl6common5ProtoS3i4i0i0TAC8tutorial11addressbook6Person11PhoneNumberZQDqFQBxZ9__lambda2TQCmZQFqZQHjFQGzZ6ResultZQJnFQJgZh':
/usr/include/dmd/phobos/std/range/primitives.d:1935: undefined reference to `_D3std9algorithm9iteration__T6joinerTSQBkQBjQBc__T9MapResultS6google8protobuf8encoding__T17toProtobufByProtoVSQBxQBt6common5ProtoS3i4i0i0TAC8tutorial11addressbook6Person11PhoneNumberZQDqFQBxZ9__lambda2TQCmZQGaZQGzFQGvZ6Result5frontMFNdZh'
.dub/build/application-debug-linux.posix-x86_64-dmd_2081-35F3EDE3A35CB79A60ECFF64D8473489/add_person.o: In function `_D6google8protobuf8decoding__T12fromProtobufTC8tutorial11addressbook11AddressBookTAhZQCdFNaKQkQBxZQCb':
/home/cconvey/r/dcarp/protbuf-d/master/examples/../src/google/protobuf/decoding.d:164: undefined reference to `_D8tutorial11addressbook11AddressBook7__ClassZ'
.dub/build/application-debug-linux.posix-x86_64-dmd_2081-35F3EDE3A35CB79A60ECFF64D8473489/add_person.o:(.data._D40TypeInfo_AC8tutorial11addressbook6Person6__initZ+0x10): undefined reference to `_D8tutorial11addressbook6Person7__ClassZ'
.dub/build/application-debug-linux.posix-x86_64-dmd_2081-35F3EDE3A35CB79A60ECFF64D8473489/add_person.o: In function `_D6google8protobuf8decoding__T12fromProtobufTC8tutorial11addressbook6PersonTAhZQBxFNaKQkQBrZQBv':
/home/cconvey/r/dcarp/protbuf-d/master/examples/../src/google/protobuf/decoding.d:164: undefined reference to `_D8tutorial11addressbook6Person7__ClassZ'
.dub/build/application-debug-linux.posix-x86_64-dmd_2081-35F3EDE3A35CB79A60ECFF64D8473489/add_person.o:(.data._D53TypeInfo_AC8tutorial11addressbook6Person11PhoneNumber6__initZ+0x10): undefined reference to `_D8tutorial11addressbook6Person11PhoneNumber7__ClassZ'
.dub/build/application-debug-linux.posix-x86_64-dmd_2081-35F3EDE3A35CB79A60ECFF64D8473489/add_person.o: In function `_D6google8protobuf8decoding__T12fromProtobufTC8tutorial11addressbook6Person11PhoneNumberTAhZQCkFNaKQkQCeZQCi':
/home/cconvey/r/dcarp/protbuf-d/master/examples/../src/google/protobuf/decoding.d:164: undefined reference to `_D8tutorial11addressbook6Person11PhoneNumber7__ClassZ'
.dub/build/application-debug-linux.posix-x86_64-dmd_2081-35F3EDE3A35CB79A60ECFF64D8473489/add_person.o:(.data._D53TypeInfo_xC8tutorial11addressbook6Person11PhoneNumber6__initZ+0x10): undefined reference to `_D8tutorial11addressbook6Person11PhoneNumber7__ClassZ'
.dub/build/application-debug-linux.posix-x86_64-dmd_2081-35F3EDE3A35CB79A60ECFF64D8473489/add_person.o:(.data._D40TypeInfo_xC8tutorial11addressbook6Person6__initZ+0x10): undefined reference to `_D8tutorial11addressbook6Person7__ClassZ'
.dub/build/application-debug-linux.posix-x86_64-dmd_2081-35F3EDE3A35CB79A60ECFF64D8473489/add_person.o: In function `_D3std5range__T5chainTSQvQt__TQpTS6google8protobuf8internal6VarintTSQCoQCn__TQCkTQBwTAhZQCvFQChQkZ6ResultZQDnFQCzQBuZQtTSQEpQEo__TQElTQDxTQEbZQExFQEjQEmZQCdTQFfTSQEyQEuQEo__T11sizedJoinerTSQHf9algorithm9iteration__T9MapResultSQHkQHg8encoding__T17toProtobufByProtoVSQIxQIt6common5ProtoS3i4i0i0TAC8tutorial11addressbook6Person11PhoneNumberZQDqFQBxZ9__lambda2TQCmZQFqZQHjFQGzZQKpTSQOmQOl__TQOiTQNuTQNyTSQPiQPh__TQPeTQLhTQLlZQPqFQLtQLwZQMwZQQfFQPrQPuQBvZQNoZQQxFNaNbNiNfQRcQNlQRiQMcQDxZSQSnQSm__TQSjTQSgTQOqTQSoTQNjTQFfZQThFQTeQPnQTkQOeQFzZQQw':
/usr/include/dmd/phobos/std/range/package.d:1204: undefined reference to `_D6google8protobuf8internal__T11sizedJoinerTS3std9algorithm9iteration__T9MapResultS6googleQDd8encoding__T17toProtobufByProtoVSQBrQEq6common5ProtoS3i4i0i0TAC8tutorial11addressbook6Person11PhoneNumberZQDqFQBxZ9__lambda2TQCmZQFuZQHoFQHeZ6Result6__initZ'
.dub/build/application-debug-linux.posix-x86_64-dmd_2081-35F3EDE3A35CB79A60ECFF64D8473489/add_person.o: In function `_D3std5range__T5chainTSQvQt__TQpTS6google8protobuf8internal6VarintTSQCoQCn__TQCkTQBwTAhZQCvFQChQkZ6ResultZQDnFQCzQBuZQtTSQEpQEo__TQElTQDxTQEbZQExFQEjQEmZQCdTQFfTSQEyQEuQEo__T11sizedJoinerTSQHf9algorithm9iteration__T9MapResultSQHkQHg8encoding__T17toProtobufByProtoVSQIxQIt6common5ProtoS3i4i0i0TAC8tutorial11addressbook6Person11PhoneNumberZQDqFQBxZ9__lambda2TQCmZQFqZQHjFQGzZQKpTSQOmQOl__TQOiTQNuTQNyTSQPiQPh__TQPeTQLhTQLlZQPqFQLtQLwZQMwZQQfFQPrQPuQBvZQNoZQQxFQQuQNdQRaQLuQDpZQOm5emptyMFNdZb':
/usr/include/dmd/phobos/std/range/package.d:966: undefined reference to `_D3std9algorithm9iteration__T6joinerTSQBkQBjQBc__T9MapResultS6google8protobuf8encoding__T17toProtobufByProtoVSQBxQBt6common5ProtoS3i4i0i0TAC8tutorial11addressbook6Person11PhoneNumberZQDqFQBxZ9__lambda2TQCmZQGaZQGzFQGvZ6Result5emptyMFNaNbNdNiNfZb'
.dub/build/application-debug-linux.posix-x86_64-dmd_2081-35F3EDE3A35CB79A60ECFF64D8473489/add_person.o: In function `_D3std5range__T5chainTSQvQt__TQpTS6google8protobuf8internal6VarintTSQCoQCn__TQCkTQBwTAhZQCvFQChQkZ6ResultZQDnFQCzQBuZQtTSQEpQEo__TQElTQDxTQEbZQExFQEjQEmZQCdTQFfTSQEyQEuQEo__T11sizedJoinerTSQHf9algorithm9iteration__T9MapResultSQHkQHg8encoding__T17toProtobufByProtoVSQIxQIt6common5ProtoS3i4i0i0TAC8tutorial11addressbook6Person11PhoneNumberZQDqFQBxZ9__lambda2TQCmZQFqZQHjFQGzZQKpTSQOmQOl__TQOiTQNuTQNyTSQPiQPh__TQPeTQLhTQLlZQPqFQLtQLwZQMwZQQfFQPrQPuQBvZQNoZQQxFQQuQNdQRaQLuQDpZQOm8popFrontMFZv':
/usr/include/dmd/phobos/std/range/package.d:987: undefined reference to `_D3std9algorithm9iteration__T6joinerTSQBkQBjQBc__T9MapResultS6google8protobuf8encoding__T17toProtobufByProtoVSQBxQBt6common5ProtoS3i4i0i0TAC8tutorial11addressbook6Person11PhoneNumberZQDqFQBxZ9__lambda2TQCmZQGaZQGzFQGvZ6Result5emptyMFNaNbNdNiNfZb'
/usr/include/dmd/phobos/std/range/package.d:988: undefined reference to `_D6google8protobuf8internal__T11sizedJoinerTS3std9algorithm9iteration__T9MapResultSQDdQCz8encoding__T17toProtobufByProtoVSQEqQEm6common5ProtoS3i4i0i0TAC8tutorial11addressbook6Person11PhoneNumberZQDqFQBxZ9__lambda2TQCmZQFqZQHkFQHaZ6Result8popFrontMFZv'
.dub/build/application-debug-linux.posix-x86_64-dmd_2081-35F3EDE3A35CB79A60ECFF64D8473489/add_person.o: In function `_D3std5range__T5chainTSQvQt__TQpTS6google8protobuf8internal6VarintTSQCoQCn__TQCkTQBwTAhZQCvFQChQkZ6ResultZQDnFQCzQBuZQtTSQEpQEo__TQElTQDxTQEbZQExFQEjQEmZQCdTQFfTSQEyQEuQEo__T11sizedJoinerTSQHf9algorithm9iteration__T9MapResultSQHkQHg8encoding__T17toProtobufByProtoVSQIxQIt6common5ProtoS3i4i0i0TAC8tutorial11addressbook6Person11PhoneNumberZQDqFQBxZ9__lambda2TQCmZQFqZQHjFQGzZQKpTSQOmQOl__TQOiTQNuTQNyTSQPiQPh__TQPeTQLhTQLlZQPqFQLtQLwZQMwZQQfFQPrQPuQBvZQNoZQQxFQQuQNdQRaQLuQDpZQOm5frontMFNdZh':
/usr/include/dmd/phobos/std/range/package.d:997: undefined reference to `_D3std9algorithm9iteration__T6joinerTSQBkQBjQBc__T9MapResultS6google8protobuf8encoding__T17toProtobufByProtoVSQBxQBt6common5ProtoS3i4i0i0TAC8tutorial11addressbook6Person11PhoneNumberZQDqFQBxZ9__lambda2TQCmZQGaZQGzFQGvZ6Result5emptyMFNaNbNdNiNfZb'
/usr/include/dmd/phobos/std/range/package.d:998: undefined reference to `_D3std9algorithm9iteration__T6joinerTSQBkQBjQBc__T9MapResultS6google8protobuf8encoding__T17toProtobufByProtoVSQBxQBt6common5ProtoS3i4i0i0TAC8tutorial11addressbook6Person11PhoneNumberZQDqFQBxZ9__lambda2TQCmZQGaZQGzFQGvZ6Result5frontMFNdZh'
.dub/build/application-debug-linux.posix-x86_64-dmd_2081-35F3EDE3A35CB79A60ECFF64D8473489/add_person.o: In function `_D3std5range__T5chainTSQvQt__TQpTS6google8protobuf8internal6VarintTSQCoQCn__TQCkTQBwTAhZQCvFQChQkZ6ResultZQDnFQCzQBuZQtTSQEpQEo__TQElTQDxTQEbZQExFQEjQEmZQCdTQFfTSQEyQEuQEo__T11sizedJoinerTSQHf9algorithm9iteration__T9MapResultSQHkQHg8encoding__T17toProtobufByProtoVSQIxQIt6common5ProtoS3i4i0i0TAC8tutorial11addressbook6Person11PhoneNumberZQDqFQBxZ9__lambda2TQCmZQFqZQHjFQGzZQKpTSQOmQOl__TQOiTQNuTQNyTSQPiQPh__TQPeTQLhTQLlZQPqFQLtQLwZQMwZQQfFQPrQPuQBvZQNoZQQxFQQuQNdQRaQLuQDpZQOm9moveFrontMFZh':
/usr/include/dmd/phobos/std/range/package.d:1026: undefined reference to `_D3std9algorithm9iteration__T6joinerTSQBkQBjQBc__T9MapResultS6google8protobuf8encoding__T17toProtobufByProtoVSQBxQBt6common5ProtoS3i4i0i0TAC8tutorial11addressbook6Person11PhoneNumberZQDqFQBxZ9__lambda2TQCmZQGaZQGzFQGvZ6Result5emptyMFNaNbNdNiNfZb'
.dub/build/application-debug-linux.posix-x86_64-dmd_2081-35F3EDE3A35CB79A60ECFF64D8473489/add_person.o: In function `_D3std5range__T5chainTSQvQt__TQpTS6google8protobuf8internal6VarintTSQCoQCn__TQCkTQBwTAhZQCvFQChQkZ6ResultZQDnFQCzQBuZQtTSQEpQEo__TQElTQDxTQEbZQExFQEjQEmZQCdTQFfTSQEyQEuQEo__T11sizedJoinerTSQHf9algorithm9iteration__T9MapResultSQHkQHg8encoding__T17toProtobufByProtoVSQIxQIt6common5ProtoS3i4i0i0TAC8tutorial11addressbook6Person11PhoneNumberZQDqFQBxZ9__lambda2TQCmZQFqZQHjFQGzZQKpTSQOmQOl__TQOiTQNuTQNyTSQPiQPh__TQPeTQLhTQLlZQPqFQLtQLwZQMwZQQfFQPrQPuQBvZQNoZQQxFQQuQNdQRaQLuQDpZQOm6lengthMFNdZm':
/usr/include/dmd/phobos/std/range/package.d:1090: undefined reference to `_D6google8protobuf8internal__T11sizedJoinerTS3std9algorithm9iteration__T9MapResultSQDdQCz8encoding__T17toProtobufByProtoVSQEqQEm6common5ProtoS3i4i0i0TAC8tutorial11addressbook6Person11PhoneNumberZQDqFQBxZ9__lambda2TQCmZQFqZQHkFQHaZ6Result6lengthMFNaNbNdNiNfZm'
.dub/build/application-debug-linux.posix-x86_64-dmd_2081-35F3EDE3A35CB79A60ECFF64D8473489/add_person.o: In function `_D3std5range__T5chainTSQvQt__TQpTS6google8protobuf8internal6VarintTSQCoQCn__TQCkTQBwTAhZQCvFQChQkZ6ResultZQDnFQCzQBuZQtTSQEpQEo__TQElTQDxTQEbZQExFQEjQEmZQCdTQFfTSQEyQEuQEo__T11sizedJoinerTSQHf9algorithm9iteration__T9MapResultSQHkQHg8encoding__T17toProtobufByProtoVSQIxQIt6common5ProtoS3i4i0i0TAC8tutorial11addressbook6Person11PhoneNumberZQDqFQBxZ9__lambda2TQCmZQFqZQHjFQGzZQKpTSQOmQOl__TQOiTQNuTQNyTSQPiQPh__TQPeTQLhTQLlZQPqFQLtQLwZQMwZQQfFQPrQPuQBvZQNoZQQxFQQuQNdQRaQLuQDpZQOm9__xtoHashFNbNeKxSQSzQSy__TQSvTQSsTQPcTQTaTQNvTQFrZQTtFQTqQPzQTwQOqQGlZQRiZm':
add_person.d:(.text._D3std5range__T5chainTSQvQt__TQpTS6google8protobuf8internal6VarintTSQCoQCn__TQCkTQBwTAhZQCvFQChQkZ6ResultZQDnFQCzQBuZQtTSQEpQEo__TQElTQDxTQEbZQExFQEjQEmZQCdTQFfTSQEyQEuQEo__T11sizedJoinerTSQHf9algorithm9iteration__T9MapResultSQHkQHg8encoding__T17toProtobufByProtoVSQIxQIt6common5ProtoS3i4i0i0TAC8tutorial11addressbook6Person11PhoneNumberZQDqFQBxZ9__lambda2TQCmZQFqZQHjFQGzZQKpTSQOmQOl__TQOiTQNuTQNyTSQPiQPh__TQPeTQLhTQLlZQPqFQLtQLwZQMwZQQfFQPrQPuQBvZQNoZQQxFQQuQNdQRaQLuQDpZQOm9__xtoHashFNbNeKxSQSzQSy__TQSvTQSsTQPcTQTaTQNvTQFrZQTtFQTqQPzQTwQOqQGlZQRiZm[_D3std5range__T5chainTSQvQt__TQpTS6google8protobuf8internal6VarintTSQCoQCn__TQCkTQBwTAhZQCvFQChQkZ6ResultZQDnFQCzQBuZQtTSQEpQEo__TQElTQDxTQEbZQExFQEjQEmZQCdTQFfTSQEyQEuQEo__T11sizedJoinerTSQHf9algorithm9iteration__T9MapResultSQHkQHg8encoding__T17toProtobufByProtoVSQIxQIt6common5ProtoS3i4i0i0TAC8tutorial11addressbook6Person11PhoneNumberZQDqFQBxZ9__lambda2TQCmZQFqZQHjFQGzZQKpTSQOmQOl__TQOiTQNuTQNyTSQPiQPh__TQPeTQLhTQLlZQPqFQLtQLwZQMwZQQfFQPrQPuQBvZQNoZQQxFQQuQNdQRaQLuQDpZQOm9__xtoHashFNbNeKxSQSzQSy__TQSvTQSsTQPcTQTaTQNvTQFrZQTtFQTqQPzQTwQOqQGlZQRiZm]+0xa5): undefined reference to `_D246TypeInfo_xS6google8protobuf8internal__T11sizedJoinerTS3std9algorithm9iteration__T9MapResultSQDdQCz8encoding__T17toProtobufByProtoVSQEqQEm6common5ProtoS3i4i0i0TAC8tutorial11addressbook6Person11PhoneNumberZQDqFQBxZ9__lambda2TQCmZQFqZQHkFQHaZ6Result6__initZ'
.dub/build/application-debug-linux.posix-x86_64-dmd_2081-35F3EDE3A35CB79A60ECFF64D8473489/add_person.o: In function `_D6google8protobuf8encoding__T10toProtobufTC8tutorial11addressbook6PersonZQBsFQBjZS3std5range__T5chainTSQvQt__TQpTSQEjQEf8internal6VarintTSQCeQCd__TQCaTQBmTAhZQClFQBxQkZ6ResultZQDdFQCpQBuZQtTSQEfQEe__TQEbTQDnTQDrZQEnFQDzQEcZQCdTQEvTSQIxQItQEo__T11sizedJoinerTSQGv9algorithm9iteration__T9MapResultSQLjQLfQKz__T17toProtobufByProtoVSQMqQMm6common5ProtoS3i4i0i0TACQMeQLyQLo11PhoneNumberZQCwFQBdZ9__lambda2TQBsZQEqZQGjFQFzZQJpTSQNcQNb__TQMyTQMkTQMoTSQNyQNx__TQNuTQKhTQKlZQOgFQKtQKwZQLwZQOvFQOhQOkQBvZQMoZQPnFQPkQMdQPqQKuQDpZQNm':
/home/cconvey/r/dcarp/protbuf-d/master/examples/../src/google/protobuf/encoding.d:162: undefined reference to `_D6google8protobuf8encoding__T17toProtobufByFieldS_D8tutorial11addressbook6Person6phonesACQBmQBgQw11PhoneNumberTCQCjQCdQBtZQDpFQpZSQEzQEv8internal__T11sizedJoinerTS3std9algorithm9iteration__T9MapResultSQHsQHoQHi__T17toProtobufByProtoVSQIzQIv6common5ProtoS3i4i0i0TQGtZQCbFQHbZ9__lambda2TQHqZQDvZQFpFQFfZ6Result'
/home/cconvey/r/dcarp/protbuf-d/master/examples/../src/google/protobuf/encoding.d:162: undefined reference to `_D6google8protobuf8encoding__T17toProtobufByFieldS_D8tutorial11addressbook6Person11lastUpdatedSQDpQDl9timestamp9TimestampTCQCtQCnQCdZQDzFQpZS3std5range__T5chainTSQGeQGa8internal6VarintTQyTSQBwQBv__TQBsTSQCkQCj__TQCgTQCdTQChZQCsFQCpQCsZ6ResultTQBpZQDpFQBxQCaZQxZQEdFQEaQEdQDfZQBo'
.dub/build/application-debug-linux.posix-x86_64-dmd_2081-35F3EDE3A35CB79A60ECFF64D8473489/add_person.o: In function `_D10add_person16promptForAddressFZC8tutorial11addressbook6Person':
/home/cconvey/r/dcarp/protbuf-d/master/examples/add_person.d:12: undefined reference to `_D8tutorial11addressbook6Person7__ClassZ'
/home/cconvey/r/dcarp/protbuf-d/master/examples/add_person.d:26: undefined reference to `_D8tutorial11addressbook6Person11PhoneNumber7__ClassZ'
.dub/build/application-debug-linux.posix-x86_64-dmd_2081-35F3EDE3A35CB79A60ECFF64D8473489/add_person.o: In function `_Dmain':
/home/cconvey/r/dcarp/protbuf-d/master/examples/add_person.d:60: undefined reference to `_D8tutorial11addressbook11AddressBook7__ClassZ'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
/usr/bin/dmd failed with exit code 1.
cconvey@cconvey-u1804 ~/r/dcarp/protbuf-d/master/examples $ dub build :add_person
Building package examples:add_person in /home/cconvey/r/dcarp/protbuf-d/master/examples/
Performing "debug" build using /usr/bin/dmd for x86_64.
examples:add_person ~master: building configuration "application"...
Running pre-build commands...
Linking...
cconvey@cconvey-u1804 ~/r/dcarp/protbuf-d/master/examples $ 

Wrong import paths in generated files

I have 2 files:
one.proto

syntax = "proto3";
package msg;

message OneData {
    bool input = 1;
}

ppp.proto

syntax = "proto3";
package msg;

import public "one.proto";

message Data {
    repeated OneData one = 1;
}

For generate I use this command

protoc -I./proto --plugin=protobuf-d/build/protoc-gen-d --d_out=source proto/ppp.proto

and get in source/msg 2 output files

// Generated by the protocol buffer compiler.  DO NOT EDIT!
// source: one.proto

module msg.one;

import google.protobuf;

enum protocVersion = 3005000;

class OneData
{
    @Proto(1) bool input = protoDefaultValue!bool;
}
// Generated by the protocol buffer compiler.  DO NOT EDIT!
// source: ppp.proto

module msg.ppp;

import google.protobuf;
import one; // <- at this point wrong import of msg.one module

enum protocVersion = 3005000;

class Data
{
    @Proto(1) OneData[] one = protoDefaultValue!(OneData[]);
}

Then I compile I get error message:

source/msg/ppp.d(7,8): Error: module `one` is in file 'one.d' which cannot be read

oneof setters behaviour

I wrote some .proto file and compiled it as structs:

syntax = "proto3";

package SomeProtocol;

message External
{
   oneof payload
   {
      Internal_msg1 i1 = 1;
      Internal_msg2 i2 = 2;
   }
}

message Internal_msg1
{
   bytes aaa = 1;
}

message Internal_msg2
{
   bytes aaa = 1;
}

Then I try to assign up i1 message and test it:

import SomeProtocol.descr;

void main()
{
    External ext;
    ext.i1.aaa = cast(byte[])[1, 2 ,3];

    assert(ext.payloadCase == External.PayloadCase.payloadNotSet); //not fail, but expected fail
    assert(ext.payloadCase == External.PayloadCase.i1); // fail
}

I.e., in this case payloadCase isn't set.

This is as designed behaviour? How to use oneof properly in this case?

Provide Dub Example of Build Configuration

Adding an example that builds a library from the D code that was generated by the protoc compiler could help with a common use case for users of this library.

The use case is a project with a server and client component that may share via a library the D code generated by this tool. In a project I am working on that does this, I am currently using the following Dub configuration:

////
// File: dub.sdl
////
authors "Vijay Nayar"
description "A library of D source files generated from a proto file."
name "proto"
targetType "library"

dependency "protobuf" version="~>0.5.4"

// Because a library with no source files will fail to build, even before preBuild commands
// are run, a file `source/dummy.d` is created.  The time-stamp of this file is also used to
// determine if the `protoc` compiler needs to be run again.

// Use the protoc compiler to generate D source files from the data.proto file if it has changed.
preBuildCommands "cd $PACKAGE_DIR ; \
    test source/dummy.d -nt data.proto || \
    { \
      echo 'Generating D source files from data.proto.' ; \
      protoc $$PROTO_PATH --plugin=/usr/local/bin/protoc-gen-d --d_opt=message-as-struct \
          --d_out=source data.proto ; \
    }"

// Use the dummy file to also note the time the last build was run.
postBuildCommands "cd $PACKAGE_DIR ; touch source/dummy.d"

This approach works but has a number of flaws. Firstly, it depends on having to know the exact path of the protoc-gen-d plugin which I have installed locally. Additionally, all these commands are specific to the exact name of the proto file.

Keep the .proto comments in the generated file

Take over the field comments from the .proto file in the generated .d message definition.
The original field names in the comments don't need to be translated (keep the original .proto comments).

Handle deprecated fields

Deprecated fields should be marked accordingly.
Eventually add option to omit them completely.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.