3

I'm trying to serialize multiple messages to a file using a protocol buffer - following the implementation shown here - but I am running into a problem whereby I can't access the FileOutputStream class as defined in <zero_copy_stream_impl.h>.

According to the API documentation, the FileOutputStream class is under the namespace google::protobuf::io - but the only definitions I can see under this namespace are CodedOutputStream, CodedInputStream, ZeroCopyOutputStream, and ZeroCopyInputStream.

Does anyone have any ideas on how to resolve this? FYI, I'm using Microsoft Visual Studio 2010 with protobuf-2.4.0a build. Here is a snippet of my code and the resulting error messages (Intellisense as well as compiler error):

int outfd = _open(fileName.c_str(), _O_CREAT | _O_BINARY | _O_APPEND | _O_WRONLY);
google::protobuf::io::ZeroCopyOutputStream *output = new google::protobuf::io::FileOutputStream(outfd);

warning C4996: '_open': This function or variable may be unsafe. Consider using _sopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.

IntelliSense: expected a type specifier

error C2061: syntax error : identifier 'FileOutputStream'

error C2039: 'FileOutputStream' : is not a member of 'google::protobuf::io'

Community
  • 1
  • 1
KnightsValour
  • 253
  • 2
  • 10
  • Sorry, but... is it possible you haven't included the header? If you look at the header, the class is right there at the top, so this seems like the only possibility. – Kenton Varda Jul 22 '14 at 16:21
  • @KentonVarda Yep - actually I figured this was the reason right after I asked the question. I was using a build of protobuf that was not compiled by me and didn't realize it was a lite version (hence the exclusion of that header by default). Anyway, I added the #include statement and it's working great now. Thanks for your help (and also for your solution to the delimited i/o with protocol buffers question!) – KnightsValour Jul 22 '14 at 17:41
  • Also, I apparently don't have enough reputation to answer my own question - hence the unsolved status... – KnightsValour Jul 22 '14 at 17:45

1 Answers1

5

It seems that my code explicitly required this:

#include <google/protobuf/io/zero_copy_stream_impl.h>

I figured it would be included by default, but apparently that's not the case. Thanks to Kenton Varda for pointing this out.

KnightsValour
  • 253
  • 2
  • 10