message XicSetHeader{
int64 TotalXicSets = 1;
string wiffName = 2;
}
XicContainer::XicContainer(std::istream *in): m_xheader(new XicHeader())
{
// m_xheader is a pointer of type XicHeader and initialized above
m_xheader->ParseFromIstream(in);
}
[libprotobuf ERROR google/protobuf/wire_format_lite.cc:532] String field 'XicHeader.wiffName' contains invalid UTF-8 data when parsing a protocol buffer. Use the 'bytes' type if you intend to send raw bytes.
I have a proto message that I have defined. I'm consuming the message on OSX using C++ and producing it on windows using C#.I'm using release 3.0.0 of Google.protobuf (NuGet on windows, compiled and built on OSX).I have read that Protobuf stores UTF-8 strings. I realize that native C# strings are UTF-16. I assumed the C# library wouldtake care of the conversion from UTF-16 to UTF-8 but that doesn't seem to be the case. The online examples that I've foundseem to just assign a string the variable (wiffName) but that doesn't seem to work.Can someone point out where I'm going wrong and how get around this? If the library doesn't handle the conversion how shouldI go about changing a UTF-16 string into a UTF-8 string in C#? Any help is really appreciatedProto File:message XicSetHeader{
int64 TotalXicSets = 1;
string wiffName = 2;
}
C# Code:var xsetHeader = new XicSetHeader();xsetHeader.TotalXicSets = xsetVec.Count;xsetHeader.WiffName = "myWiffNameHolder";using (var stream = File.Create(FileOutName(oPath))) // MemoryStream stream = new MemoryStream()){xsetHeader.WriteTo(stream);}C++ Code:// This is being passed a pointer ifstream in a good state to the encoded proto messageXicContainer::XicContainer(std::istream *in): m_xheader(new XicHeader())
{
// m_xheader is a pointer of type XicHeader and initialized above
m_xheader->ParseFromIstream(in);
}
C++ Error Message:[libprotobuf ERROR google/protobuf/wire_format_lite.cc:532] String field 'XicHeader.wiffName' contains invalid UTF-8 data when parsing a protocol buffer. Use the 'bytes' type if you intend to send raw bytes.
--
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 protobuf+unsubscribe@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
XicHeader test;
test.set_totalxics(10);
test.set_wiffname("myWiffNameHolder");
test.SerializeToOstream(of);
C++ Error Message:[libprotobuf ERROR google/protobuf/wire_format_lite.cc:532] String field 'XicHeader.wiffName' contains invalid UTF-8 data when parsing a protocol buffer. Use the 'bytes' type if you intend to send raw bytes.
--
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 protobuf+u...@googlegroups.com.
I recompiled my C++ protobuf to make sure the flags matched the flags I'm compiling withthe error message has gone away but I get an empty string out now when I deserialize.After building I did a make check and it passed the 7 tests.Any guesses as to what to kick next? Should the messages serialize to the same binary sequence?
On Jan 4, 2017, at 11:57 AM, Jamie Sherman <jamie....@gmail.com> wrote:So I forced the message to have fixed values:C#xsetHeader.TotalXicSets = 10;xsetHeader.WiffName = "myWiffNameHolder";hexdump of message:080a12106d79576966664e616d65486f6c646572C++XicHeader test;test.set_totalxics(10);test.set_wiffname("myWiffNameHolder");test.SerializeToOstream(of);hexdump of message:080a1a106d79576966664e616d65486f6c646572