|
36 | 36 | import static uk.co.real_logic.sbe.generation.java.JavaUtil.*;
|
37 | 37 | import static uk.co.real_logic.sbe.ir.GenerationUtil.*;
|
38 | 38 |
|
| 39 | +@SuppressWarnings("MethodLength") |
39 | 40 | public class JavaGenerator implements CodeGenerator
|
40 | 41 | {
|
41 | 42 | enum CodecType
|
@@ -910,26 +911,16 @@ private void generateDataDecodeMethods(
|
910 | 911 | if (characterEncoding.contains("ASCII"))
|
911 | 912 | {
|
912 | 913 | sb.append(String.format("\n" +
|
913 |
| - indent + " public void get%1$s(final Appendable value)\n" + |
| 914 | + indent + " public int get%1$s(final Appendable appendable)\n" + |
914 | 915 | indent + " {\n" +
|
915 | 916 | "%2$s" +
|
916 | 917 | indent + " final int headerLength = %3$d;\n" +
|
917 | 918 | indent + " final int limit = parentMessage.limit();\n" +
|
918 | 919 | indent + " final int dataLength = (int)%4$s;\n" +
|
919 |
| - indent + " final int dataOffset = limit + headerLength;\n" + |
| 920 | + indent + " final int dataOffset = limit + headerLength;\n\n" + |
920 | 921 | indent + " parentMessage.limit(dataOffset + dataLength);\n" +
|
921 |
| - indent + " for (int i = 0; i < dataLength; ++i)\n" + |
922 |
| - indent + " {\n" + |
923 |
| - indent + " try\n" + |
924 |
| - indent + " {\n" + |
925 |
| - indent + " final int c = buffer.getByte(dataOffset + i) & 0xFF;\n" + |
926 |
| - indent + " value.append(c > 127 ? '?' : (char)c);\n" + |
927 |
| - indent + " }\n" + |
928 |
| - indent + " catch (final java.io.IOException e)\n" + |
929 |
| - indent + " {\n" + |
930 |
| - indent + " throw new java.io.UncheckedIOException(e);\n" + |
931 |
| - indent + " }\n" + |
932 |
| - indent + " }\n" + |
| 922 | + indent + " buffer.getStringWithoutLengthAscii(dataOffset, dataLength, appendable);\n\n" + |
| 923 | + indent + " return dataLength;\n" + |
933 | 924 | indent + " }\n",
|
934 | 925 | Generators.toUpperFirstChar(propertyName),
|
935 | 926 | generateStringNotPresentConditionForAppendable(token.version(), indent),
|
@@ -1898,7 +1889,7 @@ private static CharSequence generateStringNotPresentConditionForAppendable(
|
1898 | 1889 | return String.format(
|
1899 | 1890 | indent + " if (parentMessage.actingVersion < %d)\n" +
|
1900 | 1891 | indent + " {\n" +
|
1901 |
| - indent + " return;\n" + |
| 1892 | + indent + " return 0;\n" + |
1902 | 1893 | indent + " }\n\n",
|
1903 | 1894 | sinceVersion);
|
1904 | 1895 | }
|
@@ -2010,36 +2001,40 @@ private CharSequence generatePrimitiveArrayPropertyDecode(
|
2010 | 2001 | indent + " }\n\n",
|
2011 | 2002 | propertyName,
|
2012 | 2003 | generateStringNotPresentCondition(propertyToken.version(), indent),
|
2013 |
| - fieldLength, offset, |
2014 |
| - fieldLength, fieldLength, |
| 2004 | + fieldLength, |
| 2005 | + offset, |
| 2006 | + fieldLength, |
| 2007 | + fieldLength, |
2015 | 2008 | charset(encoding.characterEncoding())));
|
2016 | 2009 |
|
2017 | 2010 | if (encoding.characterEncoding().contains("ASCII"))
|
2018 | 2011 | {
|
2019 | 2012 | sb.append(String.format("\n" +
|
2020 |
| - indent + " public void get%s(final Appendable value)\n" + |
| 2013 | + indent + " public int get%1$s(final Appendable value)\n" + |
2021 | 2014 | indent + " {\n" +
|
2022 |
| - "%s" + |
2023 |
| - indent + " for (int i = 0; i < %d ; ++i)\n" + |
| 2015 | + "%2$s" + |
| 2016 | + indent + " for (int i = 0; i < %3$d; ++i)\n" + |
2024 | 2017 | indent + " {\n" +
|
2025 |
| - indent + " final int c = buffer.getByte(this.offset + %d + i) & 0xFF;\n" + |
| 2018 | + indent + " final int c = buffer.getByte(this.offset + %4$d + i) & 0xFF;\n" + |
2026 | 2019 | indent + " if (c == 0)\n" +
|
2027 | 2020 | indent + " {\n" +
|
2028 |
| - indent + " break;\n" + |
2029 |
| - indent + " }\n" + |
| 2021 | + indent + " return i;\n" + |
| 2022 | + indent + " }\n\n" + |
2030 | 2023 | indent + " try\n" +
|
2031 | 2024 | indent + " {\n" +
|
2032 | 2025 | indent + " value.append(c > 127 ? '?' : (char)c);\n" +
|
2033 | 2026 | indent + " }\n" +
|
2034 |
| - indent + " catch (final java.io.IOException e)\n" + |
| 2027 | + indent + " catch (final java.io.IOException ex)\n" + |
2035 | 2028 | indent + " {\n" +
|
2036 |
| - indent + " throw new java.io.UncheckedIOException(e);\n" + |
| 2029 | + indent + " throw new java.io.UncheckedIOException(ex);\n" + |
2037 | 2030 | indent + " }\n" +
|
2038 |
| - indent + " }\n" + |
| 2031 | + indent + " }\n\n" + |
| 2032 | + indent + " return %3$d;\n" + |
2039 | 2033 | indent + " }\n\n",
|
2040 | 2034 | Generators.toUpperFirstChar(propertyName),
|
2041 | 2035 | generateStringNotPresentConditionForAppendable(propertyToken.version(), indent),
|
2042 |
| - fieldLength, offset)); |
| 2036 | + fieldLength, |
| 2037 | + offset)); |
2043 | 2038 | }
|
2044 | 2039 | }
|
2045 | 2040 |
|
@@ -2409,8 +2404,6 @@ private CharSequence generateFixedFlyweightCode(
|
2409 | 2404 | generateLiteral(ir.headerStructure().schemaVersionType(), Integer.toString(ir.version())),
|
2410 | 2405 | schemaIdAccessorType,
|
2411 | 2406 | schemaVersionAccessorType);
|
2412 |
| - |
2413 |
| - |
2414 | 2407 | }
|
2415 | 2408 |
|
2416 | 2409 | private CharSequence generateDecoderFlyweightCode(final String className, final Token token)
|
|
0 commit comments