@@ -932,7 +932,55 @@ private static CharSequence generateFileHeader(
932932 "# define SBE_CONSTEXPR\n " +
933933 "# define SBE_NOEXCEPT\n " +
934934 "#endif\n \n " +
935- "#include <sbe/sbe.h>\n \n " ,
935+ "#if !defined(__STDC_LIMIT_MACROS)\n " +
936+ "# define __STDC_LIMIT_MACROS 1\n " +
937+ "#endif\n " +
938+ "#include <string.h>\n " +
939+ "#include <stdint.h>\n " +
940+ "#include <limits.h>\n " +
941+ "#include <stdexcept>\n " +
942+ "#include <cstdint>\n " +
943+ "#include <limits>\n \n " +
944+ "#if defined(WIN32) || defined(_WIN32)\n " +
945+ "# define SBE_BIG_ENDIAN_ENCODE_16(v) _byteswap_ushort(v)\n " +
946+ "# define SBE_BIG_ENDIAN_ENCODE_32(v) _byteswap_ulong(v)\n " +
947+ "# define SBE_BIG_ENDIAN_ENCODE_64(v) _byteswap_uint64(v)\n " +
948+ "# define SBE_LITTLE_ENDIAN_ENCODE_16(v) (v)\n " +
949+ "# define SBE_LITTLE_ENDIAN_ENCODE_32(v) (v)\n " +
950+ "# define SBE_LITTLE_ENDIAN_ENCODE_64(v) (v)\n " +
951+ "#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__\n " +
952+ "# define SBE_BIG_ENDIAN_ENCODE_16(v) __builtin_bswap16(v)\n " +
953+ "# define SBE_BIG_ENDIAN_ENCODE_32(v) __builtin_bswap32(v)\n " +
954+ "# define SBE_BIG_ENDIAN_ENCODE_64(v) __builtin_bswap64(v)\n " +
955+ "# define SBE_LITTLE_ENDIAN_ENCODE_16(v) (v)\n " +
956+ "# define SBE_LITTLE_ENDIAN_ENCODE_32(v) (v)\n " +
957+ "# define SBE_LITTLE_ENDIAN_ENCODE_64(v) (v)\n " +
958+ "#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__\n " +
959+ "# define SBE_LITTLE_ENDIAN_ENCODE_16(v) __builtin_bswap16(v)\n " +
960+ "# define SBE_LITTLE_ENDIAN_ENCODE_32(v) __builtin_bswap32(v)\n " +
961+ "# define SBE_LITTLE_ENDIAN_ENCODE_64(v) __builtin_bswap64(v)\n " +
962+ "# define SBE_BIG_ENDIAN_ENCODE_16(v) (v)\n " +
963+ "# define SBE_BIG_ENDIAN_ENCODE_32(v) (v)\n " +
964+ "# define SBE_BIG_ENDIAN_ENCODE_64(v) (v)\n " +
965+ "#else\n " +
966+ "# error \" Byte Ordering of platform not determined. " +
967+ "Set __BYTE_ORDER__ manually before including this file.\" \n " +
968+ "#endif\n \n " +
969+ "#if defined(SBE_NO_BOUNDS_CHECK)\n " +
970+ "# define SBE_BOUNDS_CHECK_EXPECT(exp,c) (false)\n " +
971+ "#elif defined(_MSC_VER)\n " +
972+ "# define SBE_BOUNDS_CHECK_EXPECT(exp,c) (exp)\n " +
973+ "#else\n " +
974+ "# define SBE_BOUNDS_CHECK_EXPECT(exp,c) (__builtin_expect(exp,c))\n " +
975+ "#endif\n \n " +
976+ "#define SBE_NULLVALUE_INT8 (std::numeric_limits<std::int8_t>::min)()\n " +
977+ "#define SBE_NULLVALUE_INT16 (std::numeric_limits<std::int16_t>::min)()\n " +
978+ "#define SBE_NULLVALUE_INT32 (std::numeric_limits<std::int32_t>::min)()\n " +
979+ "#define SBE_NULLVALUE_INT64 (std::numeric_limits<std::int64_t>::min)()\n " +
980+ "#define SBE_NULLVALUE_UINT8 (std::numeric_limits<std::uint8_t>::max)()\n " +
981+ "#define SBE_NULLVALUE_UINT16 (std::numeric_limits<std::uint16_t>::max)()\n " +
982+ "#define SBE_NULLVALUE_UINT32 (std::numeric_limits<std::uint32_t>::max)()\n " +
983+ "#define SBE_NULLVALUE_UINT64 (std::numeric_limits<std::uint64_t>::max)()\n \n " ,
936984 String .join ("_" , namespaces ).toUpperCase (),
937985 className .toUpperCase ()));
938986
@@ -1100,7 +1148,7 @@ private CharSequence generateLoadValue(
11001148 if (primitiveType == PrimitiveType .FLOAT || primitiveType == PrimitiveType .DOUBLE )
11011149 {
11021150 final String stackUnion =
1103- (primitiveType == PrimitiveType .FLOAT ) ? "::sbe::sbe_float_as_uint_t " : "::sbe::sbe_double_as_uint_t " ;
1151+ (primitiveType == PrimitiveType .FLOAT ) ? "union sbe_float_as_uint_u " : "union sbe_double_as_uint_u " ;
11041152
11051153 sb .append (String .format (
11061154 indent + " %1$s val;\n " +
@@ -1139,7 +1187,7 @@ private CharSequence generateStoreValue(
11391187 if (primitiveType == PrimitiveType .FLOAT || primitiveType == PrimitiveType .DOUBLE )
11401188 {
11411189 final String stackUnion = primitiveType == PrimitiveType .FLOAT ?
1142- "::sbe::sbe_float_as_uint_t " : "::sbe::sbe_double_as_uint_t " ;
1190+ "union sbe_float_as_uint_u " : "union sbe_double_as_uint_u " ;
11431191
11441192 sb .append (String .format (
11451193 indent + " %1$s val;\n " +
@@ -1475,6 +1523,20 @@ private CharSequence generateFixedFlyweightCode(final String className, final in
14751523 " m_actingVersion = actingVersion;\n " +
14761524 " }\n \n " +
14771525 "public:\n " +
1526+ " enum MetaAttribute\n " +
1527+ " {\n " +
1528+ " EPOCH, TIME_UNIT, SEMANTIC_TYPE, PRESENCE\n " +
1529+ " };\n \n " +
1530+ " union sbe_float_as_uint_u\n " +
1531+ " {\n " +
1532+ " float fp_value;\n " +
1533+ " std::uint32_t uint_value;\n " +
1534+ " };\n \n " +
1535+ " union sbe_double_as_uint_u\n " +
1536+ " {\n " +
1537+ " double fp_value;\n " +
1538+ " std::uint64_t uint_value;\n " +
1539+ " };\n \n " +
14781540 " %1$s() = default;\n \n " +
14791541 " %1$s(char *buffer, const std::uint64_t bufferLength, const std::uint64_t actingVersion)\n " +
14801542 " {\n " +
@@ -1587,6 +1649,20 @@ private CharSequence generateMessageFlyweightCode(final String className, final
15871649 " m_position = codec.m_position;\n " +
15881650 " }\n \n " +
15891651 "public:\n \n " +
1652+ " enum MetaAttribute\n " +
1653+ " {\n " +
1654+ " EPOCH, TIME_UNIT, SEMANTIC_TYPE, PRESENCE\n " +
1655+ " };\n \n " +
1656+ " union sbe_float_as_uint_u\n " +
1657+ " {\n " +
1658+ " float fp_value;\n " +
1659+ " std::uint32_t uint_value;\n " +
1660+ " };\n \n " +
1661+ " union sbe_double_as_uint_u\n " +
1662+ " {\n " +
1663+ " double fp_value;\n " +
1664+ " std::uint64_t uint_value;\n " +
1665+ " };\n \n " +
15901666 "%11$s" +
15911667 " static SBE_CONSTEXPR %1$s sbeBlockLength() SBE_NOEXCEPT\n " +
15921668 " {\n " +
@@ -1766,15 +1842,15 @@ private static void generateFieldMetaAttributeMethod(
17661842 final String semanticType = encoding .semanticType () == null ? "" : encoding .semanticType ();
17671843
17681844 sb .append (String .format ("\n " +
1769- indent + " static const char * %sMetaAttribute(const ::sbe:: MetaAttribute::Attribute metaAttribute)" +
1845+ indent + " static const char * %sMetaAttribute(const MetaAttribute metaAttribute)" +
17701846 " SBE_NOEXCEPT\n " +
17711847 indent + " {\n " +
17721848 indent + " switch (metaAttribute)\n " +
17731849 indent + " {\n " +
1774- indent + " case ::sbe:: MetaAttribute::EPOCH: return \" %s\" ;\n " +
1775- indent + " case ::sbe:: MetaAttribute::TIME_UNIT: return \" %s\" ;\n " +
1776- indent + " case ::sbe:: MetaAttribute::SEMANTIC_TYPE: return \" %s\" ;\n " +
1777- indent + " case ::sbe:: MetaAttribute::PRESENCE: return \" %s\" ;\n " +
1850+ indent + " case MetaAttribute::EPOCH: return \" %s\" ;\n " +
1851+ indent + " case MetaAttribute::TIME_UNIT: return \" %s\" ;\n " +
1852+ indent + " case MetaAttribute::SEMANTIC_TYPE: return \" %s\" ;\n " +
1853+ indent + " case MetaAttribute::PRESENCE: return \" %s\" ;\n " +
17781854 indent + " }\n \n " +
17791855 indent + " return \" \" ;\n " +
17801856 indent + " }\n " ,
0 commit comments