Skip to content

Instantly share code, notes, and snippets.

@npalko
Created January 3, 2012 02:55
Show Gist options
  • Select an option

  • Save npalko/1553245 to your computer and use it in GitHub Desktop.

Select an option

Save npalko/1553245 to your computer and use it in GitHub Desktop.
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