On Wed, Jan 4, 2017 at 8:38 AM, Jamie Sherman <jamie.sher...@gmail.com>
wrote:

> 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 would
> take 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 found
> seem 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 should
> I go about changing a UTF-16 string into a UTF-8 string in C#? Any help is
> really appreciated
>
>
> Proto 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 message
>
>     XicContainer::XicContainer(std::istream *in): m_xheader(new XicHeader
> ())
>
>     {
>
>         // m_xheader is a pointer of type XicHeader and initialized above
>
>         m_xheader->ParseFromIstream(in);
>
>     }
>
Can you check if the data size is the same on both ends? If you are writing
the data into a file, make sure you are writing/reading it in binary mode.


>
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at https://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to