Commit 44d80402 authored by lahiker42's avatar lahiker42

add reserved fields


git-svn-id: https://protobuf-c.googlecode.com/svn/trunk@84 00440858-1255-0410-a3e6-75ea37f81c3a
parent 7e2742b8
...@@ -11,8 +11,9 @@ ...@@ -11,8 +11,9 @@
- License now included in major files. - License now included in major files.
- Use little-endian optimizations; fix a bug therein. - Use little-endian optimizations; fix a bug therein.
- Include 'make deb' target. - Include 'make deb' target.
0.6: NOT YET RELEASED. 0.6:
- Warning suppression for -Wcast-qual and -Wshadow. - Warning suppression for -Wcast-qual and -Wshadow.
- Support for default values of all types allowed by core protobuf. - Support for default values of all types allowed by core protobuf.
- Generate message__init functions, for when the static initializer - Generate message__init functions, for when the static initializer
isn't convenient. isn't convenient.
- add some reserved fields at the end of the various descriptors
AC_INIT(src/google/protobuf-c/protobuf-c.h) AC_INIT(src/google/protobuf-c/protobuf-c.h)
PROTOBUF_C_VERSION=0.5 PROTOBUF_C_VERSION=0.6
AM_INIT_AUTOMAKE(protobuf-c, $PROTOBUF_C_VERSION) AM_INIT_AUTOMAKE(protobuf-c, $PROTOBUF_C_VERSION)
PACKAGE=protobuf-c PACKAGE=protobuf-c
......
...@@ -131,6 +131,11 @@ struct _ProtobufCEnumDescriptor ...@@ -131,6 +131,11 @@ struct _ProtobufCEnumDescriptor
/* value-ranges, for faster lookups by number */ /* value-ranges, for faster lookups by number */
unsigned n_value_ranges; unsigned n_value_ranges;
const ProtobufCIntRange *value_ranges; const ProtobufCIntRange *value_ranges;
void *reserved1;
void *reserved2;
void *reserved3;
void *reserved4;
}; };
/* --- messages --- */ /* --- messages --- */
...@@ -146,6 +151,9 @@ struct _ProtobufCFieldDescriptor ...@@ -146,6 +151,9 @@ struct _ProtobufCFieldDescriptor
unsigned offset; unsigned offset;
const void *descriptor; /* for MESSAGE and ENUM types */ const void *descriptor; /* for MESSAGE and ENUM types */
const void *default_value; /* or NULL if no default-value */ const void *default_value; /* or NULL if no default-value */
void *reserved1;
void *reserved2;
}; };
struct _ProtobufCMessageDescriptor struct _ProtobufCMessageDescriptor
{ {
...@@ -166,6 +174,11 @@ struct _ProtobufCMessageDescriptor ...@@ -166,6 +174,11 @@ struct _ProtobufCMessageDescriptor
/* ranges, optimization for looking up fields */ /* ranges, optimization for looking up fields */
unsigned n_field_ranges; unsigned n_field_ranges;
const ProtobufCIntRange *field_ranges; const ProtobufCIntRange *field_ranges;
void *reserved1;
void *reserved2;
void *reserved3;
void *reserved4;
}; };
......
...@@ -240,7 +240,8 @@ void EnumGenerator::GenerateEnumDescriptor(io::Printer* printer) { ...@@ -240,7 +240,8 @@ void EnumGenerator::GenerateEnumDescriptor(io::Printer* printer) {
" $value_count$,\n" " $value_count$,\n"
" $lcclassname$__enum_values_by_name,\n" " $lcclassname$__enum_values_by_name,\n"
" $n_ranges$,\n" " $n_ranges$,\n"
" $lcclassname$__value_ranges\n" " $lcclassname$__value_ranges,\n"
" NULL,NULL,NULL,NULL /* reserved[1234] */\n"
"};\n"); "};\n");
} }
......
...@@ -84,7 +84,8 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer, ...@@ -84,7 +84,8 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer,
} }
printer->Print(variables, " PROTOBUF_C_OFFSETOF($classname$, $name$),\n"); printer->Print(variables, " PROTOBUF_C_OFFSETOF($classname$, $name$),\n");
printer->Print(variables, " $descriptor_addr$,\n"); printer->Print(variables, " $descriptor_addr$,\n");
printer->Print(variables, " $default_value$\n"); printer->Print(variables, " $default_value$,\n");
printer->Print(variables, " NULL,NULL /* reserved1, reserved2 */\n");
printer->Print("},\n"); printer->Print("},\n");
} }
......
...@@ -260,58 +260,6 @@ GenerateHelperFunctionDefinitions(io::Printer* printer) ...@@ -260,58 +260,6 @@ GenerateHelperFunctionDefinitions(io::Printer* printer)
); );
} }
#if 0
string MessageGenerator::
GetDefaultValueC(const FieldDescriptor *fd) {
switch (fd->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32:
return SimpleItoa(fd->default_value_int32());
case FieldDescriptor::CPPTYPE_INT64:
return SimpleItoa(fd->default_value_int64());
case FieldDescriptor::CPPTYPE_UINT32:
return SimpleItoa(fd->default_value_uint32());
case FieldDescriptor::CPPTYPE_UINT64:
return SimpleItoa(fd->default_value_uint64());
case FieldDescriptor::CPPTYPE_FLOAT:
return SimpleFtoa(fd->default_value_float());
case FieldDescriptor::CPPTYPE_DOUBLE:
return SimpleDtoa(fd->default_value_double());
case FieldDescriptor::CPPTYPE_BOOL:
return fd->default_value_bool() ? "1" : "0";
case FieldDescriptor::CPPTYPE_MESSAGE:
// NOTE: not supported by protobuf
GOOGLE_LOG(DFATAL) << "Messages can't have default values!";
return "";
case FieldDescriptor::CPPTYPE_STRING:
{
string escaped = "\"" + CEscape(fd->default_value_string()) + "\"";
if (fd->type() == FieldDescriptor::TYPE_BYTES)
{
return "{ "
+ SimpleItoa(fd->default_value_string().size())
+ ", "
+ FullNameToLower(descriptor_->full_name())
+ "__"
+ fd->name()
+ "__default_value_data }";
}
else /* STRING type */
{
return escaped;
}
}
case FieldDescriptor::CPPTYPE_ENUM:
{
const EnumValueDescriptor *vd = fd->default_value_enum();
return FullNameToUpper(vd->type()->full_name())
+ "__" + ToUpper(vd->name());
}
}
GOOGLE_LOG(DFATAL) << "missing case value";
return "";
}
#endif
void MessageGenerator:: void MessageGenerator::
GenerateMessageDescriptor(io::Printer* printer) { GenerateMessageDescriptor(io::Printer* printer) {
map<string, string> vars; map<string, string> vars;
...@@ -461,7 +409,8 @@ GenerateMessageDescriptor(io::Printer* printer) { ...@@ -461,7 +409,8 @@ GenerateMessageDescriptor(io::Printer* printer) {
" $lcclassname$__field_descriptors,\n" " $lcclassname$__field_descriptors,\n"
" $lcclassname$__field_indices_by_name,\n" " $lcclassname$__field_indices_by_name,\n"
" $n_ranges$," " $n_ranges$,"
" $lcclassname$__number_ranges\n" " $lcclassname$__number_ranges,\n"
" NULL,NULL,NULL,NULL /* reserved[1234] */\n"
"};\n"); "};\n");
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment