More unittests

git-svn-id: https://svn.kapsi.fi/jpa/nanopb@966 e3a754e5-d11d-0410-8d38-ebb782a927b9
This commit is contained in:
Petteri Aimonen
2011-08-23 18:50:09 +00:00
parent 64ac18c884
commit a353417021
6 changed files with 140 additions and 4 deletions

View File

@@ -176,9 +176,13 @@ Encoding callbacks
When encoding, the callback should write out complete fields, including the wire type and field number tag. It can write as many or as few fields as it likes. For example, if you want to write out an array as *repeated* field, you should do it all in a single call.
If the callback is used in a submessage, it will be called multiple times during a single call to `pb_encode`_. It must produce the same amount of data every time. If the callback is directly in the main message, it is called only once.
Usually you can use `pb_encode_tag_for_field`_ to encode the wire type and tag number of the field. However, if you want to encode a repeated field as a packed array, you must call `pb_encode_tag`_ instead to specify a wire type of *PB_WT_STRING*.
If the callback is used in a submessage, it will be called multiple times during a single call to `pb_encode`_. In this case, it must produce the same amount of data every time. If the callback is directly in the main message, it is called only once.
.. _`pb_encode`: reference.html#pb-encode
.. _`pb_encode_tag_for_field`: reference.html#pb-encode-tag-for-field
.. _`pb_encode_tag`: reference.html#pb-encode-tag
This callback writes out a dynamically sized string::
@@ -207,7 +211,7 @@ This callback reads multiple integers and prints them::
bool read_ints(pb_istream_t *stream, const pb_field_t *field, void *arg)
{
while (stream.bytes_left)
while (stream->bytes_left)
{
uint64_t value;
if (!pb_decode_varint(stream, &value))

View File

@@ -191,7 +191,6 @@ table.docutils {
text-align: left;
border: 1px solid gray;
border-collapse: collapse;
width: 100%;
margin: 1.5em 0em;
}
@@ -211,6 +210,11 @@ th.field-name {
table.docutils th {
font-family: monospace;
background-color: #f6f6f6;
vertical-align: middle;
}
table.field-list {
border: none;
}
div.sidebar {

View File

@@ -37,6 +37,7 @@ PB_HTYPE_REQUIRED 0x00 Verify that field exists in decoded message.
PB_HTYPE_OPTIONAL 0x10 Use separate *has_<field>* boolean to specify
whether the field is present.
PB_HTYPE_ARRAY 0x20 A repeated field with preallocated array.
Separate *<field>_count* for number of items.
PB_HTYPE_CALLBACK 0x30 A field with dynamic storage size, data is
actually a pointer to a structure containing a
callback function.
@@ -183,6 +184,17 @@ Same as `pb_encode_tag`_, except takes the parameters from a *pb_field_t* struct
This function only considers the LTYPE of the field. You can use it from your field callbacks, because the source generator writes correct LTYPE also for callback type fields.
Wire type mapping is as follows:
========================= ============
LTYPEs Wire type
========================= ============
VARINT, SVARINT PB_WT_VARINT
FIXED with data_size == 8 PB_WT_64BIT
STRING, BYTES, SUBMESSAGE PB_WT_STRING
FIXED with data_size == 4 PB_WT_32BIT
========================= ============
pb_encode_string
----------------
Writes the length of a string as varint and then contents of the string. Used for writing fields with wire type PB_WT_STRING. ::