yaml-cpp icon indicating copy to clipboard operation
yaml-cpp copied to clipboard

Conversion of uint8_t and int8_t as unsigned char

Open captain-yoshi opened this issue 3 years ago • 0 comments
trafficstars

Converting a u/int8_t (that have been encoded as an int) seems to treat the type as an unsigned char. Seems to be identical to #201.

Minimal failling example:

Node n;
int nb = 0; // 0 - 9 (same effect)
            // 10+   (bad conversion)
// Encode
n["nb"] = nb;

// Decode to uint8_t
uint8_t nb_dec = n["nb"].as<uint8_t>();

// gdb ptype nb_dec
// type = unsigned char

// gdb print nb_dec
// $1 = 48 '0'

Minimal working example: The variable nb is normally retrieved from a YAML file, so this cannot be achieved.

// Working
Node n;
uint8_t nb = 0;

// Encode
n["nb"] = nb;

// Decode to uint8_t
uint8_t nb_dec = n["nb"].as<uint8_t>();

// gdb ptype nb_dec
// type = unsigned char

// gdb print nb_dec
// $1 = 0 '\000'

As other mentioned, decoding as uint16_t works.

captain-yoshi avatar Jan 15 '22 03:01 captain-yoshi