5 #include <stddef.h> // size_t
7 /* Lightweight input stream.
8 * If buf is NULL, read but don't store bytes. */
9 typedef struct _pb_istream_t pb_istream_t;
12 bool (*callback)(pb_istream_t *stream, char *buf, size_t count);
13 void *state; // Free field for use by callback implementation
17 static inline bool pb_read(pb_istream_t *stream, char *buf, size_t count)
19 bool status = stream->callback(stream, buf, count);
20 stream->bytes_left -= count;
24 /* Lightweight output stream. */
25 typedef struct _pb_ostream_t pb_ostream_t;
28 bool (*callback)(pb_ostream_t *stream, const char *buf, size_t count);
29 void *state; // Free field for use by callback implementation
33 static inline bool pb_write(pb_ostream_t *stream, const char *buf, size_t count)
35 bool status = stream->callback(stream, buf, count);
36 stream->bytes_written += count;
40 /* List of possible decode/encode action types */
43 // Special case. Sets boolean field to true, continues parsing the data.
46 // Standard integer types
59 // Standard float types
63 // Constant-sized array
66 // Constant-sized array, with null termination
69 // Callback function pointer in field value
75 // This structure is used in constants to specify struct fields.
83 #define PB_LAST_FIELD {0,0,0,0}
85 /* --- Types to use inside generated structures. --- */
87 // Byte array and size word.
88 // Note: because of variable length array, this type cannot be directly used.
89 // Autogenerated code declares the same type of fields but with explicit length.
95 // This structure is used for giving the callback function.
96 typedef struct _pb_callback_t pb_callback_t;
97 struct _pb_callback_t {
99 bool (*decode)(pb_istream_t *stream, const pb_field_t *field, void *arg);
100 bool (*encode)(pb_ostream_t *stream, const pb_field_t *field, void *arg);
103 // Free arg for use by callback