@@ -932,7 +932,55 @@ private static CharSequence generateFileHeader(
932
932
"# define SBE_CONSTEXPR\n " +
933
933
"# define SBE_NOEXCEPT\n " +
934
934
"#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 " ,
936
984
String .join ("_" , namespaces ).toUpperCase (),
937
985
className .toUpperCase ()));
938
986
@@ -1100,7 +1148,7 @@ private CharSequence generateLoadValue(
1100
1148
if (primitiveType == PrimitiveType .FLOAT || primitiveType == PrimitiveType .DOUBLE )
1101
1149
{
1102
1150
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 " ;
1104
1152
1105
1153
sb .append (String .format (
1106
1154
indent + " %1$s val;\n " +
@@ -1139,7 +1187,7 @@ private CharSequence generateStoreValue(
1139
1187
if (primitiveType == PrimitiveType .FLOAT || primitiveType == PrimitiveType .DOUBLE )
1140
1188
{
1141
1189
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 " ;
1143
1191
1144
1192
sb .append (String .format (
1145
1193
indent + " %1$s val;\n " +
@@ -1475,6 +1523,20 @@ private CharSequence generateFixedFlyweightCode(final String className, final in
1475
1523
" m_actingVersion = actingVersion;\n " +
1476
1524
" }\n \n " +
1477
1525
"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 " +
1478
1540
" %1$s() = default;\n \n " +
1479
1541
" %1$s(char *buffer, const std::uint64_t bufferLength, const std::uint64_t actingVersion)\n " +
1480
1542
" {\n " +
@@ -1587,6 +1649,20 @@ private CharSequence generateMessageFlyweightCode(final String className, final
1587
1649
" m_position = codec.m_position;\n " +
1588
1650
" }\n \n " +
1589
1651
"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 " +
1590
1666
"%11$s" +
1591
1667
" static SBE_CONSTEXPR %1$s sbeBlockLength() SBE_NOEXCEPT\n " +
1592
1668
" {\n " +
@@ -1766,15 +1842,15 @@ private static void generateFieldMetaAttributeMethod(
1766
1842
final String semanticType = encoding .semanticType () == null ? "" : encoding .semanticType ();
1767
1843
1768
1844
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)" +
1770
1846
" SBE_NOEXCEPT\n " +
1771
1847
indent + " {\n " +
1772
1848
indent + " switch (metaAttribute)\n " +
1773
1849
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 " +
1778
1854
indent + " }\n \n " +
1779
1855
indent + " return \" \" ;\n " +
1780
1856
indent + " }\n " ,
0 commit comments