From 9fbe9a5de30c3326bd7015e91c5ba634df49ee25 Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Thu, 1 Mar 2012 13:46:52 +0200 Subject: Refactoring the field encoder interface. Replaced the confusing pb_enc_* functions with new pb_encode_* functions that have a cleaner interface. Updated documentation. Got rid of the endian_copy stuff in pb_encode.c, instead using C casts to do it automatically. This makes the code safer and also reduces binary size by about 5%. Fixes Issue 6. --- tests/encode_unittests.c | 5 ++--- tests/test_encode_callbacks.c | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/encode_unittests.c b/tests/encode_unittests.c index 166e6e8..9cdbc66 100644 --- a/tests/encode_unittests.c +++ b/tests/encode_unittests.c @@ -1,3 +1,5 @@ +#define NANOPB_INTERNALS + #include #include #include "pb_encode.h" @@ -123,7 +125,6 @@ int main() 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; @@ -132,8 +133,6 @@ int main() 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")); diff --git a/tests/test_encode_callbacks.c b/tests/test_encode_callbacks.c index f0a046d..7fa017f 100644 --- a/tests/test_encode_callbacks.c +++ b/tests/test_encode_callbacks.c @@ -29,7 +29,7 @@ bool encode_fixed32(pb_ostream_t *stream, const pb_field_t *field, const void *a return false; uint32_t value = 42; - return pb_enc_fixed32(stream, field, &value); + return pb_encode_fixed32(stream, &value); } bool encode_fixed64(pb_ostream_t *stream, const pb_field_t *field, const void *arg) @@ -38,7 +38,7 @@ bool encode_fixed64(pb_ostream_t *stream, const pb_field_t *field, const void *a return false; uint64_t value = 42; - return pb_enc_fixed64(stream, field, &value); + return pb_encode_fixed64(stream, &value); } int main() -- cgit 1.2.3-korg