diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2015-01-04 11:36:42 +0200 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2015-01-04 12:02:15 +0200 |
commit | 50c67ecec4895f65ba684e4b46b4b70980a5be6a (patch) | |
tree | 650cea85ca6c544bc6c3026c670cea63057bf721 /pb_encode.c | |
parent | b0d31468da7f644684be897cef5b0602ca10af0f (diff) |
Add int_size option for generator.
This allows overriding the integer field types to e.g. uint8_t for
saving RAM.
Update issue 139
Status: FixedInGit
Diffstat (limited to 'pb_encode.c')
-rw-r--r-- | pb_encode.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/pb_encode.c b/pb_encode.c index 5318361e..cef98861 100644 --- a/pb_encode.c +++ b/pb_encode.c @@ -567,7 +567,7 @@ static bool checkreturn pb_enc_varint(pb_ostream_t *stream, const pb_field_t *fi int64_t value = 0; /* Cases 1 and 2 are for compilers that have smaller types for bool - * or enums. */ + * or enums, and for int_size option. */ switch (field->data_size) { case 1: value = *(const int8_t*)src; break; @@ -586,6 +586,8 @@ static bool checkreturn pb_enc_uvarint(pb_ostream_t *stream, const pb_field_t *f switch (field->data_size) { + case 1: value = *(const uint8_t*)src; break; + case 2: value = *(const uint16_t*)src; break; case 4: value = *(const uint32_t*)src; break; case 8: value = *(const uint64_t*)src; break; default: PB_RETURN_ERROR(stream, "invalid data_size"); @@ -600,6 +602,8 @@ static bool checkreturn pb_enc_svarint(pb_ostream_t *stream, const pb_field_t *f switch (field->data_size) { + case 1: value = *(const int8_t*)src; break; + case 2: value = *(const int16_t*)src; break; case 4: value = *(const int32_t*)src; break; case 8: value = *(const int64_t*)src; break; default: PB_RETURN_ERROR(stream, "invalid data_size"); |