0

TinyCBORを使用してデコードおよびエンコードしたい以下のクラスがあります。

class Test { 
public:  
  int a; 
  int b;
  float c;
}

このクラスをエンコードおよびデコードするために、次のことを行っています。

int main () {

   Test t;
   t.a = 10;
   t.b = 20;
   t.c = 3.30;

   // Encode values 
   uint8_t buf[40];
   CborEncoder encoder;
   cbor_encoder_init(&encoder, &buf, sizeof(buf), 0);
   cbor_encode_int(&encoder, t.a);
   cbor_encode_int(&encoder, t.b);
   cbor_encode_float(&encoder, t.c);


   // Decode values
   CborParser parser;
   CborValue value;
   int a;
   int b;
   float c;

   cbor_parser_init(buf, sizeof(buf), 0, &parser, &value);
   cbor_value_get_int(&value, &a);
   cout << "Int A: " << a << endl;

   cbor_value_get_int(&value, &b);
   cout << "Int B: " << b << endl;

   cbor_value_get_float(&value, &c);
   cout << "Float C: " << c << endl;

   return 0;
}

問題は、私のプログラムが次のように出力することです:

A: 10
B: 10

そして、フロートの読み取りでエラーが発生しました。

何が問題になる可能性がありますか?
私も追加しようとしましcbor_value_advance_fixed(&value);たが、結果は同じです。また、 TinyCBORサイト
で複数の値をエンコード/デコードする例は見つかりません。

4

1 に答える 1