Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test_encode3.c « tests - github.com/nanopb/nanopb.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5e94be51417d400b2b0b3c81cfbf62ec629dac18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* Attempts to test all the datatypes supported by ProtoBuf.
 * Currently only tests the 'required' variety.
 */

#include <stdio.h>
#include <pb_encode.h>
#include "alltypes.pb.h"

int main()
{
    /* Initialize the structure with constants */
    AllTypes alltypes = {
        1001,
        1002,
        1003,
        1004,
        1005,
        1006,
        true,
        
        1008,
        1009,
        1010.0f,
        
        1011,
        1012,
        1013.0,
        
        "1014",
        {4, "1015"},
        {"1016", 1016},
        MyEnum_Truth,
        
        1099
    };
    
    uint8_t buffer[512];
    pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
    
    /* Now encode it and check if we succeeded. */
    if (pb_encode(&stream, AllTypes_fields, &alltypes))
    {
        fwrite(buffer, 1, stream.bytes_written, stdout);
        return 0; /* Success */
    }
    else
    {
        return 1; /* Failure */
    }
}