aakash-sahai / nanopb

Automatically exported from code.google.com/p/nanopb
zlib License
0 stars 0 forks source link

Move (nanopb).* extensions out of .proto for better compatibility with other libraries #12

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Dear Petteri,

I’m trying to get nanopb running but face a problem with REPEATED fields.

If I use your static extension I get problems when trying to compile the proto 
file for the PC into a Google C++ file.

It generates this function:

void protobuf_AddDesc_nanopb_2eproto() {
  static bool already_here = false;
  if (already_here) return;
  already_here = true;
  GOOGLE_PROTOBUF_VERIFY_VERSION;

  ::google::protobuf::protobuf_AddDesc_generator_2fdescriptor_2eproto();
  ::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
    "\n\014nanopb.proto\032\032generator/descriptor.pro"
    "to\"4\n\rNanoPBOptions\022\020\n\010max_size\030\001 \001(\005\022\021\n"
    "\tmax_count\030\002 \001(\005:>\n\006nanopb\022\035.google.prot"
    "obuf.FieldOptions\030\362\007 \001(\0132\016.NanoPBOptions", 160);
  ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
    "nanopb.proto", &protobuf_RegisterTypes);
  NanoPBOptions::default_instance_ = new NanoPBOptions();
  ::google::protobuf::internal::ExtensionSet::RegisterMessageExtension(
    &::google::protobuf::FieldOptions::default_instance(),
    1010, 11, false, false,
    &::NanoPBOptions::default_instance());
  NanoPBOptions::default_instance_->InitAsDefaultInstance();
  ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_nanopb_2eproto);
}

And I get the compile error

Error      1             error C2039: 
'protobuf_AddDesc_generator_2fdescriptor_2eproto' : is not a member of 
'google::protobuf'                
C:\Entwicklung\WaveLabs\Software\PC-Client\emUSBClient\nanopb.pb.cc    76       
    1             emUSBClient
Error      2             error C3861: 
'protobuf_AddDesc_generator_2fdescriptor_2eproto': identifier not found         
       C:\Entwicklung\WaveLabs\Software\PC-Client\emUSBClient\nanopb.pb.cc    
76           1             emUSBClient

If I don’t use your extension the C++ files are ok, but I have problems to 
fully understand the use of the call backs:

When encoding REPEATED fields, am I right that the callback is called only once 
and I have to write all fields at once?
Do I have to write the tag for each field?
I have understood your example for simples types, but I have a repeated field 
that itself is a submessage (.proto is attached) who do write the call back for 
that?
Also how to I know when decoding repeated fields with the call back how many 
fields are transmitted?

Because of the problems with the callback I would prefer to use the static 
method but I have to solve the C++ problems.

I hope you can help me.

Best
Thomas

Original issue reported on code.google.com by thomasbu...@googlemail.com on 13 Jun 2012 at 12:31

Attachments:

GoogleCodeExporter commented 9 years ago
It came out, that this is a path issue. It's importent to use the same import 
paths as the structure of your filesystem.
See http://www.mail-archive.com/protobuf@googlegroups.com/msg04129.html

Original comment by thomasbu...@googlemail.com on 15 Jun 2012 at 10:57

GoogleCodeExporter commented 9 years ago
I think this issue ca be closed it's not a defect.

Original comment by thomasbu...@googlemail.com on 19 Jun 2012 at 3:57

GoogleCodeExporter commented 9 years ago
I'll mark it as a feature request.

Summary: Using nanopb extensions in .proto files sometimes causes problems when 
generating files for other libraries. It would be nice to have one of these:

1) Ability to mark nanopb options in a separate file or in comment texts in 
.proto.

2) A script to strip out nanopb markings from .proto.

Original comment by Petteri.Aimonen on 19 Jun 2012 at 4:13

GoogleCodeExporter commented 9 years ago
No I think it's not a bug at all. If you choose the right base directory when 
running protoc.exe and nanopb and don't change any import paths.
So it really can stay like it is.

Original comment by thomasbu...@googlemail.com on 20 Jun 2012 at 6:44

GoogleCodeExporter commented 9 years ago
Sure, for C++ it probably works somewhat ok. But you are not the only one who 
has had these problems, I think it's time to actually fix it for good :)

Original comment by Petteri.Aimonen on 20 Jun 2012 at 6:18

GoogleCodeExporter commented 9 years ago

Original comment by Petteri.Aimonen on 20 Jun 2012 at 6:19

GoogleCodeExporter commented 9 years ago
This issue was updated by revision 28b0136ea4dc.

Original comment by Petteri.Aimonen on 29 Oct 2012 at 5:17

GoogleCodeExporter commented 9 years ago
This issue was updated by revision 6f8dbc73eb3e.

Still needs documentation.

Original comment by Petteri.Aimonen on 9 Mar 2013 at 12:24

GoogleCodeExporter commented 9 years ago
This issue was updated by revision 6e9e5329278b.

Update issue 77
Status: FixedInGit

Original comment by Petteri.Aimonen on 6 Jul 2013 at 1:18

GoogleCodeExporter commented 9 years ago
Fix included in nanopb-0.2.2

Original comment by Petteri.Aimonen on 18 Aug 2013 at 7:17