Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Data type definitions headers/functions externs
0003  *
0004  * @file fdatatype.h
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 
0035 #ifndef FDATATYPE_H
0036 #define FDATATYPE_H
0037 
0038 #ifdef  __cplusplus
0039 extern "C" {
0040 #endif
0041 /*---------------------------Includes-----------------------------------*/
0042 #include <ubf.h>
0043 #include <ubf_tls.h>
0044 #include <exhash.h>
0045 /*---------------------------Externs------------------------------------*/
0046 /*---------------------------Macros-------------------------------------*/
0047 #define NDRX_UBF_TYPE_LEN             32 /* Storage for field type */
0048 
0049 /* Language mode... */    
0050 #define HDR_MIN_LANG            0
0051 #define HDR_C_LANG              0         /* Default goes to C               */
0052 #define HDR_GO_LANG             1         /* Golang                          */
0053 #define HDR_JAVA_LANG           2         /* Java language mode              */
0054 #define HDR_PYTHON_LANG         3         /* Python language mode            */
0055 #define HDR_MAX_LANG            3
0056 
0057 /* first field used bytes: */
0058 #if EX_ALIGNMENT_BYTES == 8
0059 #define FF_USED_BYTES   (sizeof(BFLDID)*2)
0060 #else
0061 #define FF_USED_BYTES   sizeof(BFLDID)
0062 #endif
0063 
0064 #define UBF_MAGIC   "UBF1"
0065 #define UBF_MAGIC_SIZE   4
0066 #define CF_TEMP_BUF_MAX 1078
0067 #define EXTREAD_BUFFSIZE    16384
0068     
0069 /*---------------------------Enums--------------------------------------*/
0070 /*---------------------------Typedefs-----------------------------------*/
0071     
0072 typedef short _UBF_SHORT;
0073 typedef unsigned int _UBF_INT;
0074 typedef double UBF_DOUBLE;
0075 typedef float UBF_FLOAT;
0076 typedef long UBF_LONG;
0077 typedef char UBF_CHAR;
0078 typedef char* UBF_PTR;
0079 
0080     
0081 struct dtype_str
0082 {
0083     char *fldname;  /**< field type name                    */
0084     char *altname;  /**< alternate field type name          */
0085     _UBF_SHORT fld_type;
0086     size_t size;
0087     int aligned_size;
0088     int (*p_next) (struct dtype_str*, char *fb, int *payload_size); /* Field size used */
0089     int (*p_put_data) (struct dtype_str *t, char *fb, BFLDID bfldid, char *data, int len);
0090     int (*p_get_data_size) (struct dtype_str *t, char *data, int len, int *payload_size);
0091     int (*p_get_data) (struct dtype_str *t, char *fb, char *buf, int *len);
0092 };
0093 
0094 typedef struct dtype_str dtype_str_t;
0095 
0096 /**
0097  * Logically this extension of the dtype_str
0098  */
0099 struct dtype_ext1
0100 {
0101     _UBF_SHORT fld_type;
0102     int (*p_empty_sz) (struct dtype_ext1* t); /* size in bytes of empty entry of the data type */
0103     /**
0104      * This function puts in memory block pointe by fb an empty instance
0105      * of the data type element.
0106      */
0107     int (*p_put_empty) (struct dtype_ext1* t, char *fb, BFLDID bfldid);
0108     void (*p_dump_data) (struct dtype_ext1 *t, char *text, char *data, int *len);
0109     int hdr_size; /* header size (bytes afer which data starts in FB */
0110     /** Get temporary buffer space */
0111     char *(*p_tbuf) (struct dtype_ext1 *t, int len);
0112     /** allocate conversation buffer for user. data used for types as ubf/view */
0113     char *(*p_talloc) (struct dtype_ext1 *t, int *len);
0114     /** Fn to compare two values of data type */
0115     int (*p_cmp) (struct dtype_ext1 *t, char *val1, BFLDLEN len1, char *val2, 
0116         BFLDLEN len2, long mode);
0117     /** 
0118      * prepare ubf pointer for reading data 
0119      * @param t type descriptor
0120      * @param vstorage value storage block where to store the prepared user data
0121      * @param fld_start UBF start of the field (including header)
0122      * @return data pointer for user to return
0123      */
0124     char *(*p_prep_ubfp) (struct dtype_ext1 *t, ndrx_ubf_tls_bufval_t *vstorage, char *fld_start);
0125     
0126 };
0127 
0128 typedef struct dtype_ext1 dtype_ext1_t;
0129 
0130 /* UBF Header record */
0131 struct UBF_header
0132 {
0133     unsigned char       buffer_type;
0134     unsigned char       version;
0135     char                magic[UBF_MAGIC_SIZE];
0136     
0137     /* cache offsets: 
0138     TODO: 
0139     BFLDLEN      cache_short_off; - short is in start anyway.
0140     */
0141     BFLDLEN      cache_long_off;
0142     BFLDLEN      cache_char_off;
0143     BFLDLEN      cache_float_off;
0144     BFLDLEN      cache_double_off;
0145     BFLDLEN      cache_string_off;
0146     BFLDLEN      cache_carray_off;
0147     BFLDLEN      cache_ptr_off;
0148     BFLDLEN      cache_ubf_off;
0149     BFLDLEN      cache_view_off;
0150     
0151     BFLDLEN      buf_len; /* includes header */
0152     _UBF_INT     opts;
0153     BFLDLEN      bytes_used;
0154 #if EX_ALIGNMENT_BYTES == 8
0155     /* inject algin by 8 */
0156     long         padding1;
0157 #endif
0158     BFLDID       bfldid;
0159 #if EX_ALIGNMENT_BYTES == 8
0160     /* thus two integers get 8 too... so we are fine to start! */
0161     BFLDID       passing2;
0162 #endif
0163 };
0164 
0165 typedef struct UBF_header UBF_header_t;
0166 
0167 
0168 /*
0169  * Struct for string
0170  */
0171 struct UBF_string
0172 {
0173     BFLDID   bfldid;
0174 #if EX_ALIGNMENT_BYTES == 8
0175     BFLDID         padding;
0176 #endif
0177     BFLDLEN  dlen; /**< Data len, for faster data access */
0178     char str[1];
0179 };
0180 typedef struct UBF_string UBF_string_t;
0181 
0182 /**
0183  * Struct for string
0184  */
0185 struct UBF_carray
0186 {
0187     BFLDID   bfldid;
0188     
0189     /* TODO consider remove padding here... as duplicate of dlen */
0190 #if EX_ALIGNMENT_BYTES == 8
0191     BFLDID         padding;
0192 #endif
0193     BFLDLEN  dlen; /* Data len */
0194     /* If len is 0, then this already part of next structure?!?! */
0195     char carr[0];
0196 };
0197 typedef struct UBF_carray UBF_carray_t;
0198 
0199 /*
0200  * Struct for char
0201  */
0202 struct UBF_char
0203 {
0204     BFLDID   bfldid;
0205 #if EX_ALIGNMENT_BYTES == 8
0206     BFLDID         padding;
0207 #endif
0208     UBF_CHAR cval;
0209 };
0210 typedef struct UBF_char UBF_char_t;
0211 
0212 
0213 /*
0214  * Struct for double
0215  */
0216 struct UBF_double
0217 {
0218     BFLDID   bfldid;
0219 #if EX_ALIGNMENT_BYTES == 8
0220     BFLDID         padding;
0221 #endif
0222     UBF_DOUBLE dval;
0223 };
0224 typedef struct UBF_double UBF_double_t;
0225 
0226 /*
0227  * Struct for float
0228  */
0229 struct UBF_float
0230 {
0231     BFLDID   bfldid;
0232 #if EX_ALIGNMENT_BYTES == 8
0233     BFLDID         padding;
0234 #endif
0235     UBF_FLOAT dval;
0236 };
0237 typedef struct UBF_float UBF_float_t;
0238 
0239 /*
0240  * Struct for long
0241  */
0242 struct UBF_long
0243 {
0244     BFLDID   bfldid;
0245 #if EX_ALIGNMENT_BYTES == 8
0246     BFLDID         padding;
0247 #endif
0248     UBF_LONG lval;
0249 };
0250 typedef struct UBF_long UBF_long_t;
0251 
0252 
0253 /**
0254  * Generic (for system defined type processing)
0255  */
0256 struct UBF_generic
0257 {
0258     BFLDID bfldid;
0259 #if EX_ALIGNMENT_BYTES == 8
0260     BFLDID         padding;
0261 #endif
0262     char d[0];
0263 };
0264 typedef struct UBF_generic UBF_generic_t;
0265 
0266 /**
0267  * UBF field
0268  * The data len is extracted from ubfdata
0269  */
0270 struct UBF_ubf
0271 {
0272     BFLDID   bfldid;
0273 
0274 #if EX_ALIGNMENT_BYTES == 8
0275     BFLDID         padding;
0276 #endif
0277     /* If len is 0, then this already part of next structure. */
0278     char ubfdata[0];
0279 };
0280 typedef struct UBF_ubf UBF_ubf_t;
0281 
0282 /**
0283  * VIEW field
0284  */
0285 struct UBF_view
0286 {
0287     BFLDID   bfldid;
0288 #if EX_ALIGNMENT_BYTES == 8
0289     BFLDID         padding;
0290 #endif
0291     char vname[NDRX_VIEW_NAME_LEN+1];
0292     BFLDLEN  dlen; /* Data len */
0293     /* have some flags? -> size of long for align to 8 */
0294     long vflags;
0295     /* If len is 0, then this already part of next structure. */
0296     char data[0];
0297 };
0298 typedef struct UBF_view UBF_view_t;
0299 
0300 /**
0301  * pointer to tpallc'd field
0302  */
0303 struct UBF_ptr
0304 {
0305     BFLDID   bfldid;
0306     
0307 #if EX_ALIGNMENT_BYTES == 8
0308     BFLDID         padding;
0309 #endif
0310     UBF_PTR ptr;  /**< pointer to any tpalloc'd buffer */
0311 };
0312 typedef struct UBF_ptr UBF_ptr_t;
0313 
0314 /**
0315  * field definition found in .fd files
0316  */
0317 typedef struct UBF_field_def UBF_field_def_t;
0318 struct UBF_field_def
0319 {
0320     BFLDID bfldid;
0321     _UBF_SHORT fldtype;
0322     char fldname[UBFFLDMAX+1];
0323     
0324     EX_hash_handle hh; /* makes this structure hashable */
0325     UBF_field_def_t *next, *prev; /* next with the same hash ID! */
0326 };
0327 
0328 /*---------------------------Globals------------------------------------*/
0329 extern NDRX_API dtype_str_t G_dtype_str_map[];
0330 extern NDRX_API dtype_ext1_t G_dtype_ext1_map[];
0331 /*---------------------------Statics------------------------------------*/
0332 /*---------------------------Prototypes---------------------------------*/
0333 
0334 #ifdef  __cplusplus
0335 }
0336 #endif
0337 
0338 #endif  /* FDATATYPE_H */
0339 
0340 /* vim: set ts=4 sw=4 et smartindent: */