aboutsummaryrefslogtreecommitdiffstats
path: root/tests/callbacks/encode_callbacks.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/callbacks/encode_callbacks.c')
-rw-r--r--tests/callbacks/encode_callbacks.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/tests/callbacks/encode_callbacks.c b/tests/callbacks/encode_callbacks.c
index 3bb6a45e..6cb67b1e 100644
--- a/tests/callbacks/encode_callbacks.c
+++ b/tests/callbacks/encode_callbacks.c
@@ -4,6 +4,7 @@
#include <string.h>
#include <pb_encode.h>
#include "callbacks.pb.h"
+#include "test_helpers.h"
bool encode_string(pb_ostream_t *stream, const pb_field_t *field, void * const *arg)
{
@@ -25,19 +26,21 @@ bool encode_int32(pb_ostream_t *stream, const pb_field_t *field, void * const *a
bool encode_fixed32(pb_ostream_t *stream, const pb_field_t *field, void * const *arg)
{
+ uint32_t value = 42;
+
if (!pb_encode_tag_for_field(stream, field))
return false;
- uint32_t value = 42;
return pb_encode_fixed32(stream, &value);
}
bool encode_fixed64(pb_ostream_t *stream, const pb_field_t *field, void * const *arg)
{
+ uint64_t value = 42;
+
if (!pb_encode_tag_for_field(stream, field))
return false;
- uint64_t value = 42;
return pb_encode_fixed64(stream, &value);
}
@@ -60,8 +63,10 @@ bool encode_repeatedstring(pb_ostream_t *stream, const pb_field_t *field, void *
int main()
{
uint8_t buffer[1024];
- pb_ostream_t stream = pb_ostream_from_buffer(buffer, 1024);
- TestMessage testmessage = {};
+ pb_ostream_t stream;
+ TestMessage testmessage = {{{NULL}}};
+
+ stream = pb_ostream_from_buffer(buffer, 1024);
testmessage.stringvalue.funcs.encode = &encode_string;
testmessage.int32value.funcs.encode = &encode_int32;
@@ -79,6 +84,7 @@ int main()
if (!pb_encode(&stream, TestMessage_fields, &testmessage))
return 1;
+ SET_BINARY_MODE(stdout);
if (fwrite(buffer, stream.bytes_written, 1, stdout) != 1)
return 2;