|
| 1 | +#ifndef _SBE_H_ |
| 2 | +#define _SBE_H_ |
| 3 | + |
| 4 | +#if !defined(__STDC_LIMIT_MACROS) |
| 5 | + #define __STDC_LIMIT_MACROS 1 |
| 6 | +#endif |
| 7 | +#include <string.h> |
| 8 | +#include <stdint.h> |
| 9 | +#include <limits.h> |
| 10 | + |
| 11 | +#define E100 -50100 // E_BUF_SHORT |
| 12 | +#define E103 -50103 // VAL_UNKNWN_ENUM |
| 13 | +#define E104 -50104 // I_OUT_RANGE_NUM |
| 14 | +#define E105 -50105 // I_OUT_RANGE_NUM |
| 15 | +#define E106 -50106 // I_OUT_RANGE_NUM |
| 16 | +#define E107 -50107 // BUF_SHORT_FLYWEIGHT |
| 17 | +#define E108 -50108 // BUF_SHORT_NXT_GRP_IND |
| 18 | +#define E109 -50109 // STR_TOO_LONG_FOR_LEN_TYP |
| 19 | +#define E110 -50110 // CNT_OUT_RANGE |
| 20 | + |
| 21 | +inline const char *sbe_strerror(const int errnum) |
| 22 | +{ |
| 23 | + switch (errnum) |
| 24 | + { |
| 25 | + case E100: |
| 26 | + return "buffer too short"; |
| 27 | + case E103: |
| 28 | + return "unknown value for enum"; |
| 29 | + case E104: |
| 30 | + return "index out of range"; |
| 31 | + case E105: |
| 32 | + return "index out of range"; |
| 33 | + case E106: |
| 34 | + return "length too large"; |
| 35 | + case E107: |
| 36 | + return "buffer too short for flyweight"; |
| 37 | + case E108: |
| 38 | + return "buffer too short to support next group index"; |
| 39 | + case E109: |
| 40 | + return "std::string too long for length type"; |
| 41 | + case E110: |
| 42 | + return "count outside of allowed range"; |
| 43 | + default: |
| 44 | + return "unknown error"; |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +/* |
| 49 | + * Define some byte ordering macros |
| 50 | + */ |
| 51 | +#if defined(WIN32) || defined(_WIN32) |
| 52 | + #define SBE_BIG_ENDIAN_ENCODE_16(v) _byteswap_ushort(v) |
| 53 | + #define SBE_BIG_ENDIAN_ENCODE_32(v) _byteswap_ulong(v) |
| 54 | + #define SBE_BIG_ENDIAN_ENCODE_64(v) _byteswap_uint64(v) |
| 55 | + #define SBE_LITTLE_ENDIAN_ENCODE_16(v) (v) |
| 56 | + #define SBE_LITTLE_ENDIAN_ENCODE_32(v) (v) |
| 57 | + #define SBE_LITTLE_ENDIAN_ENCODE_64(v) (v) |
| 58 | +#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
| 59 | + #define SBE_BIG_ENDIAN_ENCODE_16(v) __builtin_bswap16(v) |
| 60 | + #define SBE_BIG_ENDIAN_ENCODE_32(v) __builtin_bswap32(v) |
| 61 | + #define SBE_BIG_ENDIAN_ENCODE_64(v) __builtin_bswap64(v) |
| 62 | + #define SBE_LITTLE_ENDIAN_ENCODE_16(v) (v) |
| 63 | + #define SBE_LITTLE_ENDIAN_ENCODE_32(v) (v) |
| 64 | + #define SBE_LITTLE_ENDIAN_ENCODE_64(v) (v) |
| 65 | +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ |
| 66 | + #define SBE_LITTLE_ENDIAN_ENCODE_16(v) __builtin_bswap16(v) |
| 67 | + #define SBE_LITTLE_ENDIAN_ENCODE_32(v) __builtin_bswap32(v) |
| 68 | + #define SBE_LITTLE_ENDIAN_ENCODE_64(v) __builtin_bswap64(v) |
| 69 | + #define SBE_BIG_ENDIAN_ENCODE_16(v) (v) |
| 70 | + #define SBE_BIG_ENDIAN_ENCODE_32(v) (v) |
| 71 | + #define SBE_BIG_ENDIAN_ENCODE_64(v) (v) |
| 72 | +#else |
| 73 | + #error "Byte Ordering of platform not determined. Set __BYTE_ORDER__ manually before including this file." |
| 74 | +#endif |
| 75 | + |
| 76 | +#if defined(SBE_NO_BOUNDS_CHECK) |
| 77 | + #define SBE_BOUNDS_CHECK_EXPECT(exp,c) (false) |
| 78 | +#elif defined(_MSC_VER) |
| 79 | + #define SBE_BOUNDS_CHECK_EXPECT(exp,c) (exp) |
| 80 | +#else |
| 81 | + #define SBE_BOUNDS_CHECK_EXPECT(exp,c) (__builtin_expect(exp,c)) |
| 82 | +#endif |
| 83 | + |
| 84 | +#define SBE_NULLVALUE_INT8 INT8_MIN |
| 85 | +#define SBE_NULLVALUE_INT16 INT16_MIN |
| 86 | +#define SBE_NULLVALUE_INT32 INT32_MIN |
| 87 | +#define SBE_NULLVALUE_INT64 INT64_MIN |
| 88 | +#define SBE_NULLVALUE_UINT8 UINT8_MAX |
| 89 | +#define SBE_NULLVALUE_UINT16 UINT16_MAX |
| 90 | +#define SBE_NULLVALUE_UINT32 UINT32_MAX |
| 91 | +#define SBE_NULLVALUE_UINT64 UINT64_MAX |
| 92 | + |
| 93 | +typedef union sbe_float_as_uint_u |
| 94 | +{ |
| 95 | + float fp_value; |
| 96 | + uint32_t uint_value; |
| 97 | +} |
| 98 | +sbe_float_as_uint_t; |
| 99 | + |
| 100 | +typedef union sbe_double_as_uint_u |
| 101 | +{ |
| 102 | + double fp_value; |
| 103 | + uint64_t uint_value; |
| 104 | +} |
| 105 | +sbe_double_as_uint_t; |
| 106 | + |
| 107 | +enum sbe_meta_attribute |
| 108 | +{ |
| 109 | + sbe_meta_attribute_EPOCH, |
| 110 | + sbe_meta_attribute_TIME_UNIT, |
| 111 | + sbe_meta_attribute_SEMANTIC_TYPE, |
| 112 | + sbe_meta_attribute_PRESENCE |
| 113 | +}; |
| 114 | + |
| 115 | +#endif |
0 commit comments