[ENet-discuss] protobuf woes and serializing to string and creating a packet out of it

Shaun Reich sreich at kde.org
Mon Feb 11 20:14:29 PST 2013


On Mon, Feb 11, 2013 at 9:40 PM, Jay Sprenkle <jsprenkle at gmail.com> wrote:

> stringstream, and the c_str() method, were designed for strings.
> If there's a binary zero in the data it will not work very well.
> You could convert to the textual stream or find a way to extract binary
> from the protocol buffer you've created. I don't know protobuf well enough
> to help you with that.
> You might try stackoverflow.com if you can't figure it out.


yep, you're absolutely right. i fixed it by doing  std::stringstream
ss2(std::string(packet->data, packet->dataLength)); and ENetPacket *packet
= enet_packet_create(ss.str().data(), ss.str().size(),
ENET_PACKET_FLAG_RELIABLE);

which should be useful for anyone else who might encounter this.

thanks for the fast response & help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20130211/698f45b6/attachment.html>


More information about the ENet-discuss mailing list