Ok,
I have solved the mystery by looking at the importer_unittest.cc
It appears that the ZeroCopyInputStream returned by SourceTree must be an
allocated object. Creating an ArrayInputStream (ZeroCopyInputStream) on the
stack and returning a reference to that object in SourceTree does not work.
Hopefully this helps someone else too...
- ajc
On Wednesday, December 13, 2017 at 3:50:34 PM UTC-8, ajcurtis84 wrote:
>
> Hello,
>
> I have written a very simple program to experiment with
> compiler::Importer. The objective is take a character array containing the
> protobuf definition and compile it for use. Below is the main data and
> logic. *Does the buffer need to be allocated?*
>
> const char* ProtoSource = "\
> syntax = \"proto3\";\
> package tutorial;\
> option java_package = \"com.example.tutorial\";\
> option java_outer_classname = \"AddressBookProtos\";\
> option csharp_namespace = \"Google.Protobuf.Examples.AddressBook\";\
> message Person {\
> string name = 1;\
> int32 id = 2;\
> string email = 3;\
> enum PhoneType {\
> MOBILE = 0;\
> HOME = 1;\
> WORK = 2;\
> }\
> message PhoneNumber {\
> string number = 1;\
> PhoneType type = 2;\
> }\
> repeated PhoneNumber phones = 4;\
> }\
> message AddressBook {\
> repeated Person people = 1;\
> }";
>
> int main(int argc, char* argv[]) {
> // Verify that the version of the library that we linked against is
> // compatible with the version of the headers we compiled against.
> GOOGLE_PROTOBUF_VERIFY_VERSION;
>
> io::ArrayInputStream instream(ProtoSource, strlen(ProtoSource));
> StringSource source(instream);
> ErrorCollector errors;
> compiler::Importer importer(&source, &errors);
> importer.Import("something");
> cout << "ALL DONE!" << endl;
>
> // Optional: Delete all global objects allocated by libprotobuf.
> google::protobuf::ShutdownProtobufLibrary();
>
> return 0;
> }
>
>
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.