+#define NANOPB_INTERNALS
+
#include <stdio.h>
#include <string.h>
#include "pb_encode.h"
return true;
}
-bool fieldcallback(pb_ostream_t *stream, const pb_field_t *field, const void *arg)
+bool fieldcallback(pb_ostream_t *stream, const pb_field_t *field, void * const *arg)
{
int value = 0x55;
if (!pb_encode_tag_for_field(stream, field))
return pb_encode_varint(stream, value);
}
-bool crazyfieldcallback(pb_ostream_t *stream, const pb_field_t *field, const void *arg)
+bool crazyfieldcallback(pb_ostream_t *stream, const pb_field_t *field, void * const *arg)
{
/* This callback writes different amount of data the second time. */
uint32_t *state = (uint32_t*)arg;
uint8_t buffer[30];
pb_ostream_t s;
uint8_t value = 1;
- int8_t svalue = -1;
int32_t max = INT32_MAX;
int32_t min = INT32_MIN;
int64_t lmax = INT64_MAX;
COMMENT("Test pb_enc_varint and pb_enc_svarint")
TEST(WRITES(pb_enc_varint(&s, &field, &value), "\x01"));
- TEST(WRITES(pb_enc_svarint(&s, &field, &svalue), "\x01"));
- TEST(WRITES(pb_enc_svarint(&s, &field, &value), "\x02"));
field.data_size = sizeof(max);
TEST(WRITES(pb_enc_svarint(&s, &field, &max), "\xfe\xff\xff\xff\x0f"));
{
uint8_t buffer[30];
pb_ostream_t s;
- char value[] = "xyzzy";
+ char value[30] = "xyzzy";
COMMENT("Test pb_enc_string")
- TEST(WRITES(pb_enc_string(&s, NULL, &value), "\x05xyzzy"))
+ TEST(WRITES(pb_enc_string(&s, &StringMessage_fields[0], &value), "\x05xyzzy"))
value[0] = '\0';
- TEST(WRITES(pb_enc_string(&s, NULL, &value), "\x00"))
+ TEST(WRITES(pb_enc_string(&s, &StringMessage_fields[0], &value), "\x00"))
+ memset(value, 'x', 30);
+ TEST(WRITES(pb_enc_string(&s, &StringMessage_fields[0], &value), "\x0Axxxxxxxxxx"))
}
{
"\x0A\x07\x0A\x05\x01\x02\x03\x04\x05"))
}
+ {
+ uint8_t buffer[20];
+ pb_ostream_t s;
+ IntegerContainer msg = {{5, {1,2,3,4,5}}};
+
+ COMMENT("Test pb_encode_delimited.")
+ TEST(WRITES(pb_encode_delimited(&s, IntegerContainer_fields, &msg),
+ "\x09\x0A\x07\x0A\x05\x01\x02\x03\x04\x05"))
+ }
+
{
uint8_t buffer[10];
pb_ostream_t s;