Skip to content

Commit f34afdc

Browse files
committed
[Java] Change back PrimitiveValue.toString() to print the byte value for a single char rather than the char itself and fix ExampleTokenListener to support this.
1 parent 8e31d5a commit f34afdc

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

sbe-samples/src/main/java/uk/co/real_logic/sbe/examples/ExampleTokenListener.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,22 @@ private static CharSequence readEncodingAsString(
203203
final PrimitiveValue constOrNotPresentValue = constOrNotPresentValue(typeToken, actingVersion);
204204
if (null != constOrNotPresentValue)
205205
{
206-
return constOrNotPresentValue.toString();
206+
if (constOrNotPresentValue.size() == 1)
207+
{
208+
try
209+
{
210+
final byte[] bytes = { (byte)constOrNotPresentValue.longValue() };
211+
return new String(bytes, constOrNotPresentValue.characterEncoding());
212+
}
213+
catch (final UnsupportedEncodingException ex)
214+
{
215+
throw new RuntimeException(ex);
216+
}
217+
}
218+
else
219+
{
220+
return constOrNotPresentValue.toString();
221+
}
207222
}
208223

209224
final StringBuilder sb = new StringBuilder();

sbe-tool/src/main/java/uk/co/real_logic/sbe/PrimitiveValue.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -364,22 +364,7 @@ public String toString()
364364
switch (representation)
365365
{
366366
case LONG:
367-
if (null != characterEncoding)
368-
{
369-
try
370-
{
371-
final byte[] bytes = new byte[]{ (byte)longValue };
372-
return new String(bytes, characterEncoding);
373-
}
374-
catch (final UnsupportedEncodingException ex)
375-
{
376-
throw new IllegalStateException(ex);
377-
}
378-
}
379-
else
380-
{
381-
return Long.toString(longValue);
382-
}
367+
return Long.toString(longValue);
383368

384369
case DOUBLE:
385370
return Double.toString(doubleValue);

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1934,7 +1934,7 @@ private CharSequence generateConstPropertyMethods(
19341934
"\n" +
19351935
indent + " public byte %s()\n" +
19361936
indent + " {\n" +
1937-
indent + " return (byte)'%s';\n" +
1937+
indent + " return (byte)%s;\n" +
19381938
indent + " }\n\n",
19391939
propertyName,
19401940
encoding.constValue()));

0 commit comments

Comments
 (0)