Created
June 14, 2012 05:15
-
-
Save wackoisgod/2928117 to your computer and use it in GitHub Desktop.
C++ Protobufs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Socket::WriteDelimitedTo(protoBuf& msg) { | |
std::ostream requestStream(&someInputStream); | |
google::protobuf::io::OstreamOutputStream rawBuffer(&requestStream); | |
google::protobuf::io::CodedOutputStream codedOutput(&rawBuffer); | |
codedOutput.WriteVarint32(msg.ByteSize()); | |
msg.SerializeToCodedStream(&codedOutput); | |
// WRITE TO SOME SOCKET! | |
boost::asio::write(socket, request); | |
} | |
public void Socket::parseDelimitedFrom(protobuf& msg) { | |
char buf[5000]; | |
google::protobuf::io::ArrayInputStream arrayInputStream(buf, 5000); | |
google::protobuf::io::CodedInputStream codedInputStream(&arrayInputStream); | |
size_t messageSize; | |
codedInputStream.ReadVarint32(&messageSize); | |
msg.ParseFromCodedStream(&codedInputStream); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment