END_TEST START_TEST (test_text_read) { uint8_t buf [] = "0.123456\t1\t42\tabde\t3.1416\t111\nbleftover text for next line"; char meta [] = "1 mympstrm label:string pi:double fighter:uint32"; MBuffer *mbuf = mbuf_create(); struct oml_message msg; struct schema *schema = schema_from_meta (meta); OmlValue values[3]; oml_value_array_init(values, 3); bzero(&msg, sizeof(msg)); mbuf_write (mbuf, buf, sizeof(buf)); int result = text_read_msg_start (&msg, mbuf); fprintf (stderr, "STRM: %d\n", msg.stream); fprintf (stderr, "SEQN: %u\n", msg.seqno); fprintf (stderr, "TS : %f\n", msg.timestamp); fprintf (stderr, "LEN : %d\n", msg.length); fprintf (stderr, "COUNT: %d\n", msg.count); result = text_read_msg_values (&msg, mbuf, schema, values); result *= 42; oml_value_array_reset(values, 3); }
END_TEST START_TEST (test_bin_read) { /* DATA_P, count=1, stream=3, { LONG_T 42 } */ uint8_t buf [] = { 0xAA, 0xAA, 0x01, 0x00, 0x00, 0x3, 0x1, // count = 1, stream = 3 0x01, 0x00, 0x00, 0x00, 0x32, // LONG_T 50 0x02, 0x54, 0x00, 0x00, 0x00, 0x05, // DOUBLE_T 42.0 0x01, 0x00, 0x10, 0xF4, 0x47, // LONG_T 1111111 0x02, 0x54, 0x00, 0x00, 0x00, 0x05, // DOUBLE_T 42.0 0x04, 0x03, 'A', 'B', 'C' // STRING_T "ABC" }; char meta [] = "3 mympstrm id:long hitchhiker:double sesame:string"; MBuffer *mbuf = mbuf_create (); struct oml_message msg; struct schema *schema = schema_from_meta (meta); OmlValue values [3]; int result; oml_value_array_init(values, 3); bzero(&msg, sizeof(msg)); int size = sizeof (buf) - 5; uint16_t nv = htons (size); memcpy (buf + 3, &nv, 2); mbuf_write (mbuf, buf, sizeof (buf)); result = bin_read_msg_start (&msg, mbuf); fail_unless(result > 0, "Unable to start reading binary message"); fprintf (stderr, "---\n"); fprintf (stderr, "STRM: %d\n", msg.stream); fprintf (stderr, "SEQN: %u\n", msg.seqno); fprintf (stderr, "TS : %f\n", msg.timestamp); fprintf (stderr, "LEN : %d\n", msg.length); fprintf (stderr, "COUNT: %d\n", msg.count); result = bin_read_msg_values (&msg, mbuf, schema, values); int i = 0; for (i = 0; i < 3; i++) { char s[64]; oml_value_to_s (&values[i], s, 64); fprintf (stderr, "%s\n", s); } oml_value_array_reset(values, 3); }
static OmlValue* create_filter_result_vector (OmlFilterDef* def, OmlValueT type, int count) { OmlValue* result = (OmlValue*)oml_malloc(count * sizeof(OmlValue)); if (!result) { logerror ("Failed to allocate memory for filter result vector\n"); return NULL; } oml_value_array_init(result, count); int i = 0; for (i = 0; i < count; i++) { if (def[i].type == OML_INPUT_VALUE) oml_value_set_type(&result[i], type); else oml_value_set_type(&result[i], def[i].type); } return result; }
/** Initialise one OmlValues. * * It is *MANDATORY* to use this function before any OmlValue setting, * otherwise, uninitialised memory might lead to various issues with dynamic * allocation. * * \param v pointer to the OmlValue to manipulate * \see oml_value_array_init */ void oml_value_init(OmlValue *v) { oml_value_array_init(v, 1); }