Extracted out protobuf parsing logic from ProtobufGen.