Modified nanopb_generator.py to generate includes for other .proto files.
[apps/agl-service-can-low-level.git] / docs / reference.rst
index 55ade5e..31f4e9f 100644 (file)
@@ -62,7 +62,7 @@ Describes a single structure field with memory position in relation to others. T
 :type:          LTYPE and HTYPE of the field.
 :data_offset:   Offset of field data, relative to the end of the previous field.
 :size_offset:   Offset of *bool* flag for optional fields or *size_t* count for arrays, relative to field data.
-:data_size:     Size of a single data entry, in bytes. For PB_LTYPE_BYTES, the size of the byte array inside the containing structure.
+:data_size:     Size of a single data entry, in bytes. For PB_LTYPE_BYTES, the size of the byte array inside the containing structure. For PB_HTYPE_CALLBACK, size of the C data type if known.
 :array_size:    Maximum number of entries in an array, if it is an array type.
 :ptr:           Pointer to default value for optional fields, or to submessage description for PB_LTYPE_SUBMESSAGE.
 
@@ -190,9 +190,9 @@ Wire type mapping is as follows:
 LTYPEs                    Wire type
 ========================= ============
 VARINT, SVARINT           PB_WT_VARINT
-FIXED with data_size == 8 PB_WT_64BIT  
+FIXED64                   PB_WT_64BIT  
 STRING, BYTES, SUBMESSAGE PB_WT_STRING 
-FIXED with data_size == 4 PB_WT_32BIT
+FIXED32                   PB_WT_32BIT
 ========================= ============
 
 pb_encode_string
@@ -214,7 +214,7 @@ Writes the length of a string as varint and then contents of the string. Used fo
 
     Each field encoder only encodes the contents of the field. The tag must be encoded separately with `pb_encode_tag_for_field`_.
 
-    You can use the field encoders from your callbacks.
+    You can use the field encoders from your callbacks. Just be aware that the pb_field_t passed to the callback is not directly compatible with most of the encoders. Instead, you must create a new pb_field_t structure and set the data_size according to the data type you pass to *src*.
 
 pb_enc_varint
 -------------
@@ -237,15 +237,26 @@ Field encoder for PB_LTYPE_SVARINT. Similar to `pb_enc_varint`_, except first zi
 
 The number is considered negative if the high-order bit of the value is set. On big endian computers, it is the highest bit of *\*src*. On little endian computers, it is the highest bit of *\*(src + field->data_size - 1)*.
 
-pb_enc_fixed
-------------
-Field encoder for PB_LTYPE_FIXED. Writes the data in little endian order. On big endian computers, reverses the order of bytes. ::
+pb_enc_fixed32
+--------------
+Field encoder for PB_LTYPE_FIXED32. Writes the data in little endian order. On big endian computers, reverses the order of bytes. ::
 
-    bool pb_enc_fixed(pb_ostream_t *stream, const pb_field_t *field, const void *src);
+    bool pb_enc_fixed32(pb_ostream_t *stream, const pb_field_t *field, const void *src);
 
-(parameters are the same as for `pb_enc_varint`_)
+:stream:        Output stream to write to.
+:field:         Not used.
+:src:           Pointer to start of the field data.
+:returns:       True on success, false on IO error.
 
-The same function is used for both integers, floats and doubles. This break encoding of double values on architectures where they are mixed endian (primarily some arm processors with hardware FPU).
+pb_enc_fixed64
+--------------
+Field encoder for PB_LTYPE_FIXED64. Writes the data in little endian order. On big endian computers, reverses the order of bytes. ::
+
+    bool pb_enc_fixed64(pb_ostream_t *stream, const pb_field_t *field, const void *src);
+
+(parameters are the same as for `pb_enc_fixed32`_)
+
+The same function is used for both integers and doubles. This breaks encoding of double values on architectures where they are mixed endian (primarily some arm processors with hardware FPU).
 
 pb_enc_bytes
 ------------
@@ -365,7 +376,12 @@ Because of memory concerns, the detection of missing required fields is not perf
 
     Each field decoder reads and decodes a single value. For arrays, the decoder is called repeatedly.
 
-    You can use the decoders from your callbacks.
+    You can use the decoders from your callbacks. Just be aware that the pb_field_t passed to the callback is not directly compatible 
+    with the *varint* field decoders. Instead, you must create a new pb_field_t structure and set the data_size according to the data type 
+    you pass to *dest*, e.g. *field.data_size = sizeof(int);*. Other fields in the *pb_field_t* don't matter.
+
+    The field decoder interface is a bit messy as a result of the interface required inside the nanopb library.
+    Eventually they may be replaced by separate wrapper functions with a more friendly interface.
 
 pb_dec_varint
 -------------
@@ -388,24 +404,43 @@ Field decoder for PB_LTYPE_SVARINT. Similar to `pb_dec_varint`_, except that it
 
 (parameters are the same as `pb_dec_varint`_)
 
-pb_dec_fixed
-------------
-Field decoder for PB_LTYPE_FIXED. ::
+pb_dec_fixed32
+--------------
+Field decoder for PB_LTYPE_FIXED32. ::
 
-    bool pb_dec_fixed(pb_istream_t *stream, const pb_field_t *field, void *dest);
+    bool pb_dec_fixed32(pb_istream_t *stream, const pb_field_t *field, void *dest);
 
-(parameters are the same as `pb_dec_varint`_)
+:stream:        Input stream to read from. 4 bytes will be read.
+:field:         Not used.
+:dest:          Pointer to destination *int32_t*, *uint32_t* or *float*.
+:returns:       True on success, false on IO errors.
 
-This function reads *field->data_size* bytes from the input stream.
+This function reads 4 bytes from the input stream.
 On big endian architectures, it then reverses the order of the bytes.
 Finally, it writes the bytes to *dest*.
 
+pb_dec_fixed64
+--------------
+Field decoder for PB_LTYPE_FIXED64. ::
+
+    bool pb_dec_fixed(pb_istream_t *stream, const pb_field_t *field, void *dest);
+
+:stream:        Input stream to read from. 8 bytes will be read.
+:field:         Not used.
+:dest:          Pointer to destination *int64_t*, *uint64_t* or *double*.
+:returns:       True on success, false on IO errors.
+
+Same as `pb_dec_fixed32`_, except this reads 8 bytes.
+
 pb_dec_bytes
 ------------
 Field decoder for PB_LTYPE_BYTES. Reads a length-prefixed block of bytes. ::
 
     bool pb_dec_bytes(pb_istream_t *stream, const pb_field_t *field, void *dest);
 
+**Note:** This is an internal function that is not useful in decoder callbacks. To read bytes fields in callbacks, use 
+*stream->bytes_left* and `pb_read`_.
+
 :stream:        Input stream to read from.
 :field:         Field description structure. Only *field->data_size* matters.
 :dest:          Pointer to a structure similar to pb_bytes_array_t.
@@ -419,6 +454,9 @@ Field decoder for PB_LTYPE_STRING. Reads a length-prefixed string. ::
 
     bool pb_dec_string(pb_istream_t *stream, const pb_field_t *field, void *dest);
 
+**Note:** This is an internal function that is not useful in decoder callbacks. To read string fields in callbacks, use 
+*stream->bytes_left* and `pb_read`_.
+
 :stream:        Input stream to read from.
 :field:         Field description structure. Only *field->data_size* matters.
 :dest:          Pointer to a character array of size *field->data_size*.
@@ -432,6 +470,9 @@ Field decoder for PB_LTYPE_SUBMESSAGE. Calls `pb_decode`_ to perform the actual
 
     bool pb_dec_submessage(pb_istream_t *stream, const pb_field_t *field, void *dest)
 
+**Note:** This is an internal function that is not useful in decoder callbacks. To read submessage fields in callbacks, use 
+`pb_decode`_ directly.
+
 :stream:        Input stream to read from.
 :field:         Field description structure. Only *field->ptr* matters.
 :dest:          Pointer to the destination structure.