Created
January 3, 2012 02:55
-
-
Save npalko/1553245 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| type_protobuf::Test target; | |
| std::string raw; | |
| google::protobuf::io::StringOutputStream output(&raw); | |
| google::protobuf::io::CodedOutputStream encoder(&output); | |
| encoder.WriteVarint32(target.ByteSize()); | |
| target.SerializeToCodedStream(&encoder); | |
| type_protobuf::Test msg; | |
| google::protobuf::io::ArrayInputStream input(raw.data(), raw.size()); | |
| google::protobuf::io::CodedInputStream decoder(&input); | |
| decoder.SetTotalBytesLimit(std::numeric_limits<int>::max(), std::numeric_limits<int>::max()); | |
| uint32_t limit = 0; | |
| decoder.ReadVarint32(&limit); | |
| int old = decoder.PushLimit(limit); | |
| msg.ParseFromCodedStream(&decoder); | |
| decoder.PopLimit(old); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment