nDPI serialization: uint key compression, new deserialization API
This commit is contained in:
+33
-39
@@ -3418,7 +3418,8 @@ void serializerUnitTest() {
|
|||||||
assert(ndpi_init_deserializer(&deserializer, &serializer) != -1);
|
assert(ndpi_init_deserializer(&deserializer, &serializer) != -1);
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
ndpi_serialization_element_type et = ndpi_deserialize_get_nextitem_type(&deserializer);
|
ndpi_serialization_type kt, et;
|
||||||
|
et = ndpi_deserialize_get_item_type(&deserializer, &kt);
|
||||||
|
|
||||||
if(et == ndpi_serialization_unknown)
|
if(et == ndpi_serialization_unknown)
|
||||||
break;
|
break;
|
||||||
@@ -3427,62 +3428,55 @@ void serializerUnitTest() {
|
|||||||
ndpi_string ks, vs;
|
ndpi_string ks, vs;
|
||||||
float vf;
|
float vf;
|
||||||
|
|
||||||
|
switch(kt) {
|
||||||
|
case ndpi_serialization_uint32:
|
||||||
|
ndpi_deserialize_key_uint32(&deserializer, &k32);
|
||||||
|
if(trace) printf("%u=", k32);
|
||||||
|
break;
|
||||||
|
case ndpi_serialization_string:
|
||||||
|
ndpi_deserialize_key_string(&deserializer, &ks);
|
||||||
|
if (trace) {
|
||||||
|
u_int8_t bkp = ks.str[ks.str_len];
|
||||||
|
ks.str[ks.str_len] = '\0';
|
||||||
|
printf("%s=", ks.str);
|
||||||
|
ks.str[ks.str_len] = bkp;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("Unsupported TLV key type %u\n", kt);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch(et) {
|
switch(et) {
|
||||||
case ndpi_serialization_uint32_uint32:
|
case ndpi_serialization_uint32:
|
||||||
assert(ndpi_deserialize_uint32_uint32(&deserializer, &k32, &v32) != -1);
|
assert(ndpi_deserialize_value_uint32(&deserializer, &v32) != -1);
|
||||||
if(trace) printf("%u=%u\n", k32, v32);
|
if(trace) printf("%u\n", v32);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ndpi_serialization_uint32_string:
|
case ndpi_serialization_string:
|
||||||
assert(ndpi_deserialize_uint32_string(&deserializer, &k32, &vs) != -1);
|
assert(ndpi_deserialize_value_string(&deserializer, &vs) != -1);
|
||||||
if(trace) {
|
if(trace) {
|
||||||
u_int8_t bkp = vs.str[vs.str_len];
|
u_int8_t bkp = vs.str[vs.str_len];
|
||||||
|
|
||||||
vs.str[vs.str_len] = '\0';
|
vs.str[vs.str_len] = '\0';
|
||||||
printf("%u=%s\n", k32, vs.str);
|
printf("%s\n", vs.str);
|
||||||
vs.str[vs.str_len] = bkp;
|
vs.str[vs.str_len] = bkp;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ndpi_serialization_string_string:
|
case ndpi_serialization_float:
|
||||||
assert(ndpi_deserialize_string_string(&deserializer, &ks, &vs) != -1);
|
assert(ndpi_deserialize_value_float(&deserializer, &vf) != -1);
|
||||||
if(trace) {
|
if(trace) printf("%f\n", vf);
|
||||||
u_int8_t bkpk = ks.str[ks.str_len], bkp = vs.str[vs.str_len];
|
|
||||||
|
|
||||||
ks.str[ks.str_len] = vs.str[vs.str_len] = '\0';
|
|
||||||
printf("%s=%s\n", ks.str, vs.str);
|
|
||||||
ks.str[ks.str_len] = bkpk, vs.str[vs.str_len] = bkp;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ndpi_serialization_string_uint32:
|
|
||||||
assert(ndpi_deserialize_string_uint32(&deserializer, &ks, &v32) != -1);
|
|
||||||
if(trace) {
|
|
||||||
u_int8_t bkpk = ks.str[ks.str_len];
|
|
||||||
|
|
||||||
ks.str[ks.str_len] = '\0';
|
|
||||||
printf("%s=%u\n", ks.str, v32);
|
|
||||||
ks.str[ks.str_len] = bkpk;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ndpi_serialization_string_float:
|
|
||||||
assert(ndpi_deserialize_string_float(&deserializer, &ks, &vf) != -1);
|
|
||||||
if(trace) {
|
|
||||||
u_int8_t bkpk = ks.str[ks.str_len];
|
|
||||||
|
|
||||||
ks.str[ks.str_len] = '\0';
|
|
||||||
printf("%s=%f\n", ks.str, vf);
|
|
||||||
ks.str[ks.str_len] = bkpk;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
if (trace) printf("\n");
|
||||||
printf("serializerUnitTest: unsupported type %u detected!\n", et);
|
printf("serializerUnitTest: unsupported type %u detected!\n", et);
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ndpi_deserialize_next(&deserializer);
|
||||||
}
|
}
|
||||||
|
|
||||||
ndpi_term_serializer(&serializer);
|
ndpi_term_serializer(&serializer);
|
||||||
|
|||||||
+11
-26
@@ -867,33 +867,18 @@ extern "C" {
|
|||||||
u_int8_t *serialized_buffer,
|
u_int8_t *serialized_buffer,
|
||||||
u_int32_t serialized_buffer_len);
|
u_int32_t serialized_buffer_len);
|
||||||
|
|
||||||
ndpi_serialization_element_type ndpi_deserialize_get_nextitem_type(ndpi_deserializer *deserializer);
|
ndpi_serialization_type ndpi_deserialize_get_item_type(ndpi_deserializer *deserializer, ndpi_serialization_type *key_type);
|
||||||
|
int ndpi_deserialize_next(ndpi_deserializer *deserializer);
|
||||||
|
|
||||||
int ndpi_deserialize_uint32_uint32(ndpi_deserializer *deserializer,
|
int ndpi_deserialize_key_uint32(ndpi_deserializer *deserializer, u_int32_t *key);
|
||||||
u_int32_t *key, u_int32_t *value);
|
int ndpi_deserialize_key_string(ndpi_deserializer *deserializer, ndpi_string *key);
|
||||||
int ndpi_deserialize_uint32_uint64(ndpi_deserializer *deserializer,
|
|
||||||
u_int32_t *key, u_int64_t *value);
|
int ndpi_deserialize_value_uint32(ndpi_deserializer *deserializer, u_int32_t *value);
|
||||||
int ndpi_deserialize_uint32_int32(ndpi_deserializer *deserializer,
|
int ndpi_deserialize_value_uint64(ndpi_deserializer *deserializer, u_int64_t *value);
|
||||||
u_int32_t *key, int32_t *value);
|
int ndpi_deserialize_value_int32(ndpi_deserializer *deserializer, int32_t *value);
|
||||||
int ndpi_deserialize_uint32_int64(ndpi_deserializer *deserializer,
|
int ndpi_deserialize_value_int64(ndpi_deserializer *deserializer, int64_t *value);
|
||||||
u_int32_t *key, int64_t *value);
|
int ndpi_deserialize_value_float(ndpi_deserializer *deserializer, float *value);
|
||||||
int ndpi_deserialize_uint32_float(ndpi_deserializer *deserializer,
|
int ndpi_deserialize_value_string(ndpi_deserializer *deserializer, ndpi_string *value);
|
||||||
u_int32_t *key, float *value);
|
|
||||||
int ndpi_deserialize_uint32_string(ndpi_deserializer *deserializer,
|
|
||||||
u_int32_t *key, ndpi_string *value);
|
|
||||||
int ndpi_deserialize_string_int32(ndpi_deserializer *deserializer,
|
|
||||||
ndpi_string *key, int32_t *value);
|
|
||||||
int ndpi_deserialize_string_int64(ndpi_deserializer *deserializer,
|
|
||||||
ndpi_string *key, int64_t *value);
|
|
||||||
int ndpi_deserialize_string_uint32(ndpi_deserializer *deserializer,
|
|
||||||
ndpi_string *key, u_int32_t *value);
|
|
||||||
int ndpi_deserialize_string_uint64(ndpi_deserializer *deserializer,
|
|
||||||
ndpi_string *key, u_int64_t *value);
|
|
||||||
int ndpi_deserialize_string_string(ndpi_deserializer *deserializer,
|
|
||||||
ndpi_string *key, ndpi_string *value);
|
|
||||||
int ndpi_deserialize_string_float(ndpi_deserializer *deserializer,
|
|
||||||
ndpi_string *key, float *value);
|
|
||||||
int ndpi_deserialize_end_of_record(ndpi_deserializer *deserializer);
|
|
||||||
|
|
||||||
/* Data analysis */
|
/* Data analysis */
|
||||||
struct ndpi_analyze_struct* ndpi_alloc_data_analysis(u_int16_t _max_series_len);
|
struct ndpi_analyze_struct* ndpi_alloc_data_analysis(u_int16_t _max_series_len);
|
||||||
|
|||||||
+11
-23
@@ -1343,29 +1343,17 @@ typedef enum {
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
ndpi_serialization_unknown = 0,
|
ndpi_serialization_unknown = 0,
|
||||||
ndpi_serialization_end_of_record,
|
ndpi_serialization_end_of_record,
|
||||||
ndpi_serialization_uint32_uint32,
|
ndpi_serialization_uint8,
|
||||||
ndpi_serialization_uint32_uint64,
|
ndpi_serialization_uint16,
|
||||||
ndpi_serialization_uint32_string,
|
ndpi_serialization_uint32,
|
||||||
ndpi_serialization_string_int32,
|
ndpi_serialization_uint64,
|
||||||
ndpi_serialization_string_int64,
|
ndpi_serialization_int8,
|
||||||
ndpi_serialization_string_uint32,
|
ndpi_serialization_int16,
|
||||||
ndpi_serialization_string_uint64,
|
ndpi_serialization_int32,
|
||||||
ndpi_serialization_string_float,
|
ndpi_serialization_int64,
|
||||||
ndpi_serialization_string_string,
|
ndpi_serialization_float,
|
||||||
ndpi_serialization_uint32_int32,
|
ndpi_serialization_string
|
||||||
ndpi_serialization_uint32_int64,
|
} ndpi_serialization_type;
|
||||||
ndpi_serialization_uint32_float,
|
|
||||||
|
|
||||||
/* 32/64 bit types are automatically encoded/decoded as 8/16 bit */
|
|
||||||
ndpi_serialization_uint32_uint16,
|
|
||||||
ndpi_serialization_uint32_uint8,
|
|
||||||
ndpi_serialization_uint32_int16,
|
|
||||||
ndpi_serialization_uint32_int8,
|
|
||||||
ndpi_serialization_string_uint16,
|
|
||||||
ndpi_serialization_string_uint8,
|
|
||||||
ndpi_serialization_string_int16,
|
|
||||||
ndpi_serialization_string_int8
|
|
||||||
} ndpi_serialization_element_type;
|
|
||||||
|
|
||||||
#define NDPI_SERIALIZER_STATUS_COMMA (1 << 0)
|
#define NDPI_SERIALIZER_STATUS_COMMA (1 << 0)
|
||||||
#define NDPI_SERIALIZER_STATUS_ARRAY (1 << 1)
|
#define NDPI_SERIALIZER_STATUS_ARRAY (1 << 1)
|
||||||
|
|||||||
+453
-456
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user