コード例 #1
0
ファイル: tests-cbor.c プロジェクト: ryankurte/RIOT
static void test_double_invalid(void)
{
    TEST_ASSERT_EQUAL_INT(0, cbor_serialize_double(&empty_stream, 0));
    TEST_ASSERT_EQUAL_INT(0, empty_stream.pos);


    double val_double = 0;
    TEST_ASSERT_EQUAL_INT(0, cbor_deserialize_double(&invalid_stream, 0, &val_double));
}
コード例 #2
0
ファイル: tests-cbor.c プロジェクト: AdamRLukaitis/RIOT
/**
 * Manual test for testing the cbor_stream_decode function
 */
void test_stream_decode(void)
{
    cbor_clear(&stream);

    cbor_serialize_int(&stream, 1);
    cbor_serialize_uint64_t(&stream, 2llu);
    cbor_serialize_int64_t(&stream, 3);
    cbor_serialize_int64_t(&stream, -5);
    cbor_serialize_bool(&stream, true);
#ifndef CBOR_NO_FLOAT
    cbor_serialize_float_half(&stream, 1.1f);
    cbor_serialize_float(&stream, 1.5f);
    cbor_serialize_double(&stream, 2.0);
#endif /* CBOR_NO_FLOAT */
    cbor_serialize_byte_string(&stream, "abc");
    cbor_serialize_unicode_string(&stream, "def");

    cbor_serialize_array(&stream, 2);
    cbor_serialize_int(&stream, 0);
    cbor_serialize_int(&stream, 1);

    cbor_serialize_array_indefinite(&stream);
    cbor_serialize_int(&stream, 10);
    cbor_serialize_int(&stream, 11);
    cbor_write_break(&stream);

    cbor_serialize_map(&stream, 2);
    cbor_serialize_int(&stream, 1);
    cbor_serialize_byte_string(&stream, "1");
    cbor_serialize_int(&stream, 2);
    cbor_serialize_byte_string(&stream, "2");

    cbor_serialize_map_indefinite(&stream);
    cbor_serialize_int(&stream, 10);
    cbor_serialize_byte_string(&stream, "10");
    cbor_serialize_int(&stream, 11);
    cbor_serialize_byte_string(&stream, "11");
    cbor_write_break(&stream);

#ifndef CBOR_NO_SEMANTIC_TAGGING
#ifndef CBOR_NO_CTIME
    time_t rawtime;
    time(&rawtime);
    struct tm *timeinfo = localtime(&rawtime);
    cbor_serialize_date_time(&stream, timeinfo);
    cbor_serialize_date_time_epoch(&stream, rawtime);
#endif /* CBOR_NO_CTIME */

    /* decoder should skip the tag and print 'unsupported' here */
    cbor_write_tag(&stream, 2);
    cbor_serialize_byte_string(&stream, "1");
#endif /* CBOR_NO_SEMANTIC_TAGGING */

    cbor_stream_decode(&stream);
}
コード例 #3
0
ファイル: senml_pack.cpp プロジェクト: osdomotics/osd-contiki
int SenMLPack::fieldsToCbor()
{
    int res = 0 ;
    if(this->_bn.length() > 0 ){
        res += cbor_serialize_int(SENML_CBOR_BN_LABEL);
        res += cbor_serialize_unicode_string(this->_bn.c_str());
    }
    if(this->_bu){
        res += cbor_serialize_int(SENML_CBOR_BU_LABEL);
        res += cbor_serialize_unicode_string(senml_units_names[this->_bu]);
    }
    if(!isnan(this->_bt)){
        res += cbor_serialize_int(SENML_CBOR_BT_LABEL);
        res += cbor_serialize_double(this->_bt);
    }
    return res;
}
コード例 #4
0
int SenMLRecord::fieldsToCbor()
{
    int res = 0;
    if(this->_name.length() > 0){
        res += cbor_serialize_int(SENML_CBOR_N_LABEL);
        res += cbor_serialize_unicode_string(this->_name.c_str());
    }
    if(!isnan(this->_time)){
        res += cbor_serialize_int(SENML_CBOR_T_LABEL);
        res += cbor_serialize_double(this->_time);
    }
    if(this->_unit != SENML_UNIT_NONE){
        res += cbor_serialize_int(SENML_CBOR_U_LABEL);
        res += cbor_serialize_unicode_string(senml_units_names[this->_unit]);
    }
    if(this->_updateTime != 0){
        res += cbor_serialize_int(SENML_CBOR_UT_LABEL);
        res += cbor_serialize_int(this->_updateTime);
    }
    return res;
}