Skip to content

Commit

Permalink
Init values in basetypes
Browse files Browse the repository at this point in the history
Signed-off-by: Siebren Weertman <[email protected]>
  • Loading branch information
Siebren Weertman committed Oct 11, 2024
1 parent b76f818 commit be8d1f7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define EXI_STRING_MAX_LEN 64
#define EXI_BYTE_ARRAY_MAX_LEN 350

#define EXI_BASETYPES_MAX_OCTETS_SUPPORTED 20
#define EXI_BASETYPES_MAX_OCTETS_SUPPORTED 25

#define EXI_BASETYPES_OCTET_SEQ_FLAG_MASK 0x80
#define EXI_BASETYPES_OCTET_SEQ_VALUE_MASK 0x7F
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ static int exi_basetypes_decoder_read_unsigned(exi_bitstream_t* stream, exi_unsi

while (exi_unsigned->octets_count < EXI_BASETYPES_MAX_OCTETS_SUPPORTED)
{
int error;
error = exi_bitstream_read_octet(stream, current_octet);
int error = exi_bitstream_read_octet(stream, current_octet);
if (error != EXI_ERROR__NO_ERROR)
{
return error;
Expand Down Expand Up @@ -55,10 +54,10 @@ static int exi_basetypes_decoder_read_unsigned(exi_bitstream_t* stream, exi_unsi
*****************************************************************************/
int exi_basetypes_decoder_bool(exi_bitstream_t* stream, int* value)
{
int error;
uint32_t bit;
uint32_t bit = 0;

int error = exi_bitstream_read_bits(stream, 1, &bit);

error = exi_bitstream_read_bits(stream, 1, &bit);
if (error == EXI_ERROR__NO_ERROR)
{
*value = (bit) ? 1 : 0;
Expand Down Expand Up @@ -89,8 +88,7 @@ int exi_basetypes_decoder_bytes(exi_bitstream_t* stream, size_t bytes_len, uint8

for (size_t n = 0; n < bytes_len; n++)
{
int error;
error = exi_bitstream_read_octet(stream, current_byte);
int error = exi_bitstream_read_octet(stream, current_byte);
if (error != EXI_ERROR__NO_ERROR)
{
return error;
Expand Down Expand Up @@ -119,11 +117,11 @@ int exi_basetypes_decoder_nbit_uint(exi_bitstream_t* stream, size_t bit_count, u

int exi_basetypes_decoder_uint_8(exi_bitstream_t* stream, uint8_t* value)
{
int error;
exi_unsigned_t exi_unsigned;
uint32_t result;
exi_unsigned_t exi_unsigned = {0};
uint32_t result = 0;

int error = exi_basetypes_decoder_read_unsigned(stream, &exi_unsigned);

error = exi_basetypes_decoder_read_unsigned(stream, &exi_unsigned);
if (error != EXI_ERROR__NO_ERROR)
{
return error;
Expand All @@ -149,11 +147,10 @@ int exi_basetypes_decoder_uint_8(exi_bitstream_t* stream, uint8_t* value)

int exi_basetypes_decoder_uint_16(exi_bitstream_t* stream, uint16_t* value)
{
int error;
exi_unsigned_t exi_unsigned;
uint32_t result;
exi_unsigned_t exi_unsigned = {0};
uint32_t result = 0;

error = exi_basetypes_decoder_read_unsigned(stream, &exi_unsigned);
int error = exi_basetypes_decoder_read_unsigned(stream, &exi_unsigned);
if (error != EXI_ERROR__NO_ERROR)
{
return error;
Expand All @@ -179,10 +176,9 @@ int exi_basetypes_decoder_uint_16(exi_bitstream_t* stream, uint16_t* value)

int exi_basetypes_decoder_uint_32(exi_bitstream_t* stream, uint32_t* value)
{
int error;
exi_unsigned_t exi_unsigned;
exi_unsigned_t exi_unsigned = {0};

error = exi_basetypes_decoder_read_unsigned(stream, &exi_unsigned);
int error = exi_basetypes_decoder_read_unsigned(stream, &exi_unsigned);
if (error != EXI_ERROR__NO_ERROR)
{
return error;
Expand All @@ -206,10 +202,9 @@ int exi_basetypes_decoder_uint_32(exi_bitstream_t* stream, uint32_t* value)

int exi_basetypes_decoder_uint_64(exi_bitstream_t* stream, uint64_t* value)
{
int error;
exi_unsigned_t exi_unsigned;
exi_unsigned_t exi_unsigned = {0};

error = exi_basetypes_decoder_read_unsigned(stream, &exi_unsigned);
int error = exi_basetypes_decoder_read_unsigned(stream, &exi_unsigned);
if (error != EXI_ERROR__NO_ERROR)
{
return error;
Expand All @@ -234,10 +229,9 @@ int exi_basetypes_decoder_unsigned(exi_bitstream_t* stream, exi_unsigned_t* valu
*****************************************************************************/
int exi_basetypes_decoder_integer_8(exi_bitstream_t* stream, int8_t* value)
{
int sign;
int error;
int sign = 0;

error = exi_basetypes_decoder_bool(stream, &sign);
int error = exi_basetypes_decoder_bool(stream, &sign);
if (error != EXI_ERROR__NO_ERROR)
{
return error;
Expand All @@ -259,10 +253,9 @@ int exi_basetypes_decoder_integer_8(exi_bitstream_t* stream, int8_t* value)

int exi_basetypes_decoder_integer_16(exi_bitstream_t* stream, int16_t* value)
{
int sign;
int error;
int sign = 0;

error = exi_basetypes_decoder_bool(stream, &sign);
int error = exi_basetypes_decoder_bool(stream, &sign);
if (error != EXI_ERROR__NO_ERROR)
{
return error;
Expand Down Expand Up @@ -291,10 +284,9 @@ int exi_basetypes_decoder_integer_16(exi_bitstream_t* stream, int16_t* value)

int exi_basetypes_decoder_integer_32(exi_bitstream_t* stream, int32_t* value)
{
int sign;
int error;
int sign = 0;

error = exi_basetypes_decoder_bool(stream, &sign);
int error = exi_basetypes_decoder_bool(stream, &sign);
if (error != EXI_ERROR__NO_ERROR)
{
return error;
Expand Down Expand Up @@ -323,10 +315,9 @@ int exi_basetypes_decoder_integer_32(exi_bitstream_t* stream, int32_t* value)

int exi_basetypes_decoder_integer_64(exi_bitstream_t* stream, int64_t* value)
{
int sign;
int error;
int sign = 0;

error = exi_basetypes_decoder_bool(stream, &sign);
int error = exi_basetypes_decoder_bool(stream, &sign);
if (error != EXI_ERROR__NO_ERROR)
{
return error;
Expand All @@ -348,10 +339,9 @@ int exi_basetypes_decoder_integer_64(exi_bitstream_t* stream, int64_t* value)

int exi_basetypes_decoder_signed(exi_bitstream_t* stream, exi_signed_t* value)
{
int sign;
int error;
int sign = 0;

error = exi_basetypes_decoder_bool(stream, &sign);
int error = exi_basetypes_decoder_bool(stream, &sign);
if (error != EXI_ERROR__NO_ERROR)
{
return error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ int exi_basetypes_encoder_bool(exi_bitstream_t* stream, int value)
stream->status_callback(EXI_DEBUG__BASETYPES_ENCODE_BOOL, 0, (int)value, 0);
}
{% endif %}
int error;
uint32_t bit = (value) ? 1 : 0;

error = exi_bitstream_write_bits(stream, 1, bit);
int error = exi_bitstream_write_bits(stream, 1, bit);

return error;
}
Expand All @@ -76,8 +75,7 @@ int exi_basetypes_encoder_bytes(exi_bitstream_t* stream, size_t bytes_len, const

for (size_t n = 0; n < bytes_len; n++)
{
int error;
error = exi_bitstream_write_octet(stream, *current_byte);
int error = exi_bitstream_write_octet(stream, *current_byte);
if (error != EXI_ERROR__NO_ERROR)
{
return error;
Expand Down Expand Up @@ -105,11 +103,10 @@ int exi_basetypes_encoder_uint_8(exi_bitstream_t* stream, uint8_t value)
stream->status_callback(EXI_DEBUG__BASETYPES_ENCODE_UINT_8, 0, (int)value, 0);
}
{% endif %}
int error;
exi_unsigned_t exi_unsigned;
uint32_t result = (uint32_t)value;

error = exi_basetypes_convert_to_unsigned(&exi_unsigned, result, EXI_BASETYPES_UINT8_MAX_OCTETS);
int error = exi_basetypes_convert_to_unsigned(&exi_unsigned, result, EXI_BASETYPES_UINT8_MAX_OCTETS);
if (error != EXI_ERROR__NO_ERROR)
{
return error;
Expand All @@ -126,11 +123,10 @@ int exi_basetypes_encoder_uint_16(exi_bitstream_t* stream, uint16_t value)
stream->status_callback(EXI_DEBUG__BASETYPES_ENCODE_UINT_16, 0, (int)value, 0);
}
{% endif %}
int error;
exi_unsigned_t exi_unsigned;
uint32_t result = (uint32_t)value;

error = exi_basetypes_convert_to_unsigned(&exi_unsigned, result, EXI_BASETYPES_UINT16_MAX_OCTETS);
int error = exi_basetypes_convert_to_unsigned(&exi_unsigned, result, EXI_BASETYPES_UINT16_MAX_OCTETS);
if (error != EXI_ERROR__NO_ERROR)
{
return error;
Expand All @@ -147,10 +143,9 @@ int exi_basetypes_encoder_uint_32(exi_bitstream_t* stream, uint32_t value)
stream->status_callback(EXI_DEBUG__BASETYPES_ENCODE_UINT_32, 0, (int)value, 0);
}
{% endif %}
int error;
exi_unsigned_t exi_unsigned;

error = exi_basetypes_convert_to_unsigned(&exi_unsigned, value, EXI_BASETYPES_UINT32_MAX_OCTETS);
int error = exi_basetypes_convert_to_unsigned(&exi_unsigned, value, EXI_BASETYPES_UINT32_MAX_OCTETS);
if (error != EXI_ERROR__NO_ERROR)
{
return error;
Expand All @@ -161,10 +156,9 @@ int exi_basetypes_encoder_uint_32(exi_bitstream_t* stream, uint32_t value)

int exi_basetypes_encoder_uint_64(exi_bitstream_t* stream, uint64_t value)
{
int error;
exi_unsigned_t exi_unsigned;

error = exi_basetypes_convert_64_to_unsigned(&exi_unsigned, value);
int error = exi_basetypes_convert_64_to_unsigned(&exi_unsigned, value);
if (error != EXI_ERROR__NO_ERROR)
{
return error;
Expand All @@ -189,10 +183,9 @@ int exi_basetypes_encoder_integer_8(exi_bitstream_t* stream, int8_t value)
stream->status_callback(EXI_DEBUG__BASETYPES_ENCODE_INT_8, 0, (int)value, 0);
}
{% endif %}
int error;
int sign = (value < 0) ? 1 : 0;

error = exi_basetypes_encoder_bool(stream, sign);
int error = exi_basetypes_encoder_bool(stream, sign);
if (error != EXI_ERROR__NO_ERROR)
{
return error;
Expand All @@ -216,10 +209,9 @@ int exi_basetypes_encoder_integer_16(exi_bitstream_t* stream, int16_t value)
stream->status_callback(EXI_DEBUG__BASETYPES_ENCODE_INT_16, 0, (int)value, 0);
}
{% endif %}
int error;
int sign = (value < 0) ? 1 : 0;

error = exi_basetypes_encoder_bool(stream, sign);
int error = exi_basetypes_encoder_bool(stream, sign);
if (error != EXI_ERROR__NO_ERROR)
{
return error;
Expand All @@ -243,10 +235,9 @@ int exi_basetypes_encoder_integer_32(exi_bitstream_t* stream, int32_t value)
stream->status_callback(EXI_DEBUG__BASETYPES_ENCODE_INT_32, 0, (int)value, 0);
}
{% endif %}
int error;
int sign = (value < 0) ? 1 : 0;

error = exi_basetypes_encoder_bool(stream, sign);
int error = exi_basetypes_encoder_bool(stream, sign);
if (error != EXI_ERROR__NO_ERROR)
{
return error;
Expand All @@ -264,10 +255,9 @@ int exi_basetypes_encoder_integer_32(exi_bitstream_t* stream, int32_t value)

int exi_basetypes_encoder_integer_64(exi_bitstream_t* stream, int64_t value)
{
int error;
int sign = (value < 0) ? 1 : 0;

error = exi_basetypes_encoder_bool(stream, sign);
int error = exi_basetypes_encoder_bool(stream, sign);
if (error != EXI_ERROR__NO_ERROR)
{
return error;
Expand All @@ -285,9 +275,7 @@ int exi_basetypes_encoder_integer_64(exi_bitstream_t* stream, int64_t value)

int exi_basetypes_encoder_signed(exi_bitstream_t* stream, const exi_signed_t* value)
{
int error;

error = exi_basetypes_encoder_bool(stream, value->is_negative);
int error = exi_basetypes_encoder_bool(stream, value->is_negative);
if (error != EXI_ERROR__NO_ERROR)
{
return error;
Expand Down

0 comments on commit be8d1f7

Please sign in to comment.