From 18b2ebe3df26009ef6b2aeb0670a396e876fca25 Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Sun, 4 Jun 2017 00:17:22 +0100 Subject: Added nb_match functionality --- netbytes.h | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'netbytes.h') diff --git a/netbytes.h b/netbytes.h index a73dcc6..3960142 100644 --- a/netbytes.h +++ b/netbytes.h @@ -124,6 +124,21 @@ typedef struct netbyte_load uint8_t *buf; } netbyte_load; +typedef struct nb_tok +{ + int sign; + int type_size; + int len; + int arr; +} nb_tok; + +typedef struct nb_tok_arr +{ + int size; + int len; + nb_tok *tok; +} nb_tok_arr; + int nb_u8_create( nb_u8 *s, uint8_t val ); int nb_u8arr_create( nb_u8arr *s, __NBT_U8ARR_LEN len, uint8_t *val ); int nb_u16_create( nb_u16 *s, uint16_t val ); @@ -150,35 +165,27 @@ int nb_free(netbyte_store *store); int nb_load( netbyte_store *store, uint8_t *data ); int nb_count( netbyte_store *store ); int nb_type( netbyte_store *store, int count, __NBT_TYPED **type ); -int nb_val( netbyte_store *store, int count, uint8_t **val ); +int nb_val( netbyte_store *store, int count, __nb_type **type ); int nb_fread( netbyte_store *store, int fd); //print all all values in netbyte string int nb_print(netbyte_store *store); -//check if netbyte matches particular format -int nb_match(netbyte_store *store, int size); +/* +check if netbyte matches particular format +-1 err +1 not match +0 match +*/ +int nb_match(netbyte_store *store, nb_tok_arr *pattern); #define SIGN_UNSIGNED 1 #define SIGN_SIGNED 2 -typedef struct nb_tok -{ - int sign; - int type_size; - int len; - int arr; -} nb_tok; - -typedef struct nb_tok_arr -{ - int size; - int len; - nb_tok *tok; -} nb_tok_arr; - nb_tok_arr *nb_tok_create(int size); int nb_tok_add(nb_tok_arr *arr, int sign, int type_size, int len, int farr); void nb_tok_destroy(nb_tok_arr *arr); +int nb_parse(char *str, nb_tok_arr *arr); + #endif \ No newline at end of file -- cgit v1.2.3