Revert "Add pb_decode_noinit and use it from pb_dec_submessage."
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>
Sun, 26 Aug 2012 07:05:46 +0000 (10:05 +0300)
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>
Sun, 26 Aug 2012 07:05:46 +0000 (10:05 +0300)
The patch breaks default values inside submessage arrays (I think).
Have to add test cases and check back.

This reverts commit f1d7640fe1be0f150f604c72108ea516222c2505.

docs/reference.rst
pb_decode.c
pb_decode.h

index 371c155..ec9aec5 100644 (file)
@@ -322,16 +322,6 @@ In addition to EOF, the pb_decode implementation supports terminating a message
 
 For optional fields, this function applies the default value and sets *has_<field>* to false if the field is not present.
 
-pb_decode_noinit
-----------------
-Same as `pb_decode`_, except does not apply the default values to fields. ::
-
-    bool pb_decode_noinit(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct);
-
-(parameters are the same as for `pb_decode`_.)
-
-The destination structure should be filled with zeros before calling this function. Doing a *memset* manually can be slightly faster than using `pb_decode`_ if you don't need any default values.
-
 pb_skip_varint
 --------------
 Skip a varint_ encoded integer without decoding it. ::
index 601dc74..9d65504 100644 (file)
@@ -415,11 +415,13 @@ static void pb_message_set_to_defaults(const pb_field_t fields[], void *dest_str
  * Decode all fields *
  *********************/
 
-bool checkreturn pb_decode_noinit(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct)
+bool checkreturn pb_decode(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct)
 {
     uint8_t fields_seen[(PB_MAX_REQUIRED_FIELDS + 7) / 8] = {0}; /* Used to check for required fields */
     pb_field_iterator_t iter;
     
+    pb_message_set_to_defaults(fields, dest_struct);
+    
     pb_field_init(&iter, fields, dest_struct);
     
     while (stream->bytes_left)
@@ -468,12 +470,6 @@ bool checkreturn pb_decode_noinit(pb_istream_t *stream, const pb_field_t fields[
     return true;
 }
 
-bool checkreturn pb_decode(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct)
-{
-    pb_message_set_to_defaults(fields, dest_struct);
-    return pb_decode_noinit(stream, fields, dest_struct);
-}
-
 /* Field decoders */
 
 bool pb_decode_svarint(pb_istream_t *stream, int64_t *dest)
@@ -619,7 +615,7 @@ bool checkreturn pb_dec_submessage(pb_istream_t *stream, const pb_field_t *field
     if (field->ptr == NULL)
         PB_RETURN_ERROR(stream, "invalid field descriptor");
     
-    status = pb_decode_noinit(&substream, (pb_field_t*)field->ptr, dest);
+    status = pb_decode(&substream, (pb_field_t*)field->ptr, dest);
     pb_close_string_substream(stream, &substream);
     return status;
 }
index 483665e..ad45efb 100644 (file)
@@ -48,12 +48,6 @@ bool pb_read(pb_istream_t *stream, uint8_t *buf, size_t count);
  */
 bool pb_decode(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct);
 
-/* Same as pb_decode, except does not initialize the destination structure
- * to default values. This is slightly faster if you need no default values
- * and just do memset(struct, 0, sizeof(struct)) yourself.
- */
-bool pb_decode_noinit(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct);
-
 /* --- Helper functions ---
  * You may want to use these from your caller or callbacks.
  */