#ifndef __NETBYTES_H #define __NETBYTES_H #include #include #include #include #include #include /* types that are supported */ #define NBT_NONE 0x00 /* maybe not yet prepared type */ #define NBT_U8 0x01 /* single unsigned 8 bits */ #define NBT_U8ARRAY 0x02 /* u8 array */ #define NBT_U16 0x03 /**/ #define NBT_U16ARRAY 0x04 /**/ #define NBT_U32 0x05 /**/ #define NBT_U32ARRAY 0x06 /**/ #define NBT_U64 0x07 /**/ #define NBT_U64ARRAY 0x08 /**/ #define NBT_I8 0x09 /**/ #define NBT_I8ARRAY 0x0A /**/ #define NBT_I16 0x0B /**/ #define NBT_I16ARRAY 0x0C /**/ #define NBT_I32 0x0D /**/ #define NBT_I32ARRAY 0x0E /**/ #define NBT_I64 0x0F /**/ #define NBT_I64ARRAY 0x10 /**/ #define NBT_F16 0x11 /**/ #define NBT_F32 0x12 /**/ #define NBT_F64 0x13 /**/ #define NBT_F80 0x14 /**/ #define NBT_NULL 0x15 /* official empty type */ #define NBT_LIST 0x16 /* list of data */ /* data typed used */ #define __NBT_SIZE uint32_t #define __NBT_TYPED uint8_t #define __NBT_U8ARR_LEN uint16_t #define __NBT_MINIMAL_SIZE (sizeof(__NBT_SIZE)) #define __NBT_MAX_TYPES (256) //creating netbyte structure typedef struct __nb_type { __NBT_TYPED type; uint8_t *nb_val; } __nb_type; typedef struct netbyte_store { __NBT_SIZE size; int count; __nb_type types[__NBT_MAX_TYPES]; } netbyte_store; typedef struct nb_u8 { __NBT_TYPED type; uint8_t val; } nb_u8; typedef struct nb_u8arr { __NBT_TYPED type; __NBT_U8ARR_LEN len; uint8_t *val; } nb_u8arr; //loading/parsing netbyte structure typedef struct netbyte_load { __NBT_SIZE size; uint8_t *buf; } netbyte_load; 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_init( netbyte_store *store ); int nb_add_u8( netbyte_store *store, nb_u8 *u8 ); int nb_add_u8arr( netbyte_store *store, nb_u8arr *u8arr ); uint8_t *nb_create( 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_fread( netbyte_store *store, int fd); #endif