From 1efabef4cfce64a373f014ee43bab371a82f7e87 Mon Sep 17 00:00:00 2001 From: Luca Deri Date: Sun, 26 Sep 2021 22:55:15 +0200 Subject: Added API for handling compressed bitmaps ndpi_bitmap* ndpi_bitmap_alloc(); void ndpi_bitmap_free(ndpi_bitmap* b); u_int64_t ndpi_bitmap_cardinality(ndpi_bitmap* b); void ndpi_bitmap_set(ndpi_bitmap* b, u_int32_t value); void ndpi_bitmap_unset(ndpi_bitmap* b, u_int32_t value); bool ndpi_bitmap_isset(ndpi_bitmap* b, u_int32_t value); void ndpi_bitmap_clear(ndpi_bitmap* b); size_t ndpi_bitmap_serialize(ndpi_bitmap* b, char **buf); ndpi_bitmap* ndpi_bitmap_deserialize(char *buf); based on https://github.com/RoaringBitmap/CRoaring --- example/ndpiReader.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'example') diff --git a/example/ndpiReader.c b/example/ndpiReader.c index ab93872f2..c5e235b61 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -4363,6 +4363,36 @@ void jitterUnitTest() { /* *********************************************** */ +void compressedBitmapUnitTest() { + ndpi_bitmap *b = ndpi_bitmap_alloc(), *b1; + u_int i, trace = 0; + size_t ser; + char *buf; + + for(i=0; i<1000; i++) { + u_int32_t v = rand(); + + if(trace) printf("%u ", v); + ndpi_bitmap_set(b, v); + assert(ndpi_bitmap_isset(b, v)); + } + + if(trace) printf("\n"); + + ser = ndpi_bitmap_serialize(b, &buf); + assert(ser > 0); + + if(trace) printf("len: %lu\n", ser); + b1 = ndpi_bitmap_deserialize(buf); + assert(b1); + + ndpi_free(buf); + ndpi_bitmap_free(b); + ndpi_bitmap_free(b1); +} + +/* *********************************************** */ + /** @brief MAIN FUNCTION **/ @@ -4392,7 +4422,7 @@ int original_main(int argc, char **argv) { printf("nDPI Library version mismatch: please make sure this code and the nDPI library are in sync\n"); return(-1); } - + if(!skip_unit_tests) { #ifndef DEBUG_TRACE /* Skip tests when debugging */ @@ -4423,6 +4453,7 @@ int original_main(int argc, char **argv) { ndpi_self_check_host_match(); analysisUnitTest(); rulesUnitTest(); + compressedBitmapUnitTest(); #endif } -- cgit v1.2.3