aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_encode_callbacks.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_encode_callbacks.c')
-rw-r--r--tests/test_encode_callbacks.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/test_encode_callbacks.c b/tests/test_encode_callbacks.c
index da2ee28e..f0a046de 100644
--- a/tests/test_encode_callbacks.c
+++ b/tests/test_encode_callbacks.c
@@ -15,6 +15,32 @@ bool encode_string(pb_ostream_t *stream, const pb_field_t *field, const void *ar
return pb_encode_string(stream, (uint8_t*)str, strlen(str));
}
+bool encode_int32(pb_ostream_t *stream, const pb_field_t *field, const void *arg)
+{
+ if (!pb_encode_tag_for_field(stream, field))
+ return false;
+
+ return pb_encode_varint(stream, 42);
+}
+
+bool encode_fixed32(pb_ostream_t *stream, const pb_field_t *field, const void *arg)
+{
+ if (!pb_encode_tag_for_field(stream, field))
+ return false;
+
+ uint32_t value = 42;
+ return pb_enc_fixed32(stream, field, &value);
+}
+
+bool encode_fixed64(pb_ostream_t *stream, const pb_field_t *field, const void *arg)
+{
+ if (!pb_encode_tag_for_field(stream, field))
+ return false;
+
+ uint64_t value = 42;
+ return pb_enc_fixed64(stream, field, &value);
+}
+
int main()
{
uint8_t buffer[1024];
@@ -22,6 +48,15 @@ int main()
TestMessage testmessage = {};
testmessage.stringvalue.funcs.encode = &encode_string;
+ testmessage.int32value.funcs.encode = &encode_int32;
+ testmessage.fixed32value.funcs.encode = &encode_fixed32;
+ testmessage.fixed64value.funcs.encode = &encode_fixed64;
+
+ testmessage.has_submsg = true;
+ testmessage.submsg.stringvalue.funcs.encode = &encode_string;
+ testmessage.submsg.int32value.funcs.encode = &encode_int32;
+ testmessage.submsg.fixed32value.funcs.encode = &encode_fixed32;
+ testmessage.submsg.fixed64value.funcs.encode = &encode_fixed64;
if (!pb_encode(&stream, TestMessage_fields, &testmessage))
return 1;