Skip to content

Commit f83f986

Browse files
committed
[Java] Fix bug in DTO decodeFrom signature.
It was using `short` for `actingVersion` and `blockLength`, but the inner call to `Decoder#wrap` expects an `int` (in the `uint16` range) for both arguments. There were a bunch of down/narrowing casts in tests, which I should have spotted when doing the port and have now been removed.
1 parent ae8a211 commit f83f986

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ private static void generateDecodeFrom(
470470
.append("\n")
471471
.append(indent).append("public static ").append(dtoClassName).append(" decodeFrom(")
472472
.append("DirectBuffer buffer, int offset, ")
473-
.append("short actingBlockLength, short actingVersion)\n")
473+
.append("int actingBlockLength, int actingVersion)\n")
474474
.append(indent).append("{\n")
475475
.append(indent).append(INDENT).append(decoderClassName).append(" decoder = new ")
476476
.append(decoderClassName).append("();\n")

sbe-tool/src/propertyTest/java/uk/co/real_logic/sbe/properties/DtosPropertyTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@ void javaDtoEncodeShouldBeTheInverseOfDtoDecode(
101101
generatedClassLoader.loadClass(packageName + ".TestMessageDto");
102102

103103
final Method decodeFrom =
104-
dtoClass.getMethod("decodeFrom", DirectBuffer.class, int.class, short.class, short.class);
104+
dtoClass.getMethod("decodeFrom", DirectBuffer.class, int.class, int.class, int.class);
105105

106106
final Method encodeWith =
107107
dtoClass.getMethod("encodeWithHeaderWith", dtoClass, MutableDirectBuffer.class, int.class);
108108

109109
final int inputLength = encodedMessage.length();
110110
final ExpandableArrayBuffer inputBuffer = encodedMessage.buffer();
111111
final MessageHeaderDecoder header = new MessageHeaderDecoder().wrap(inputBuffer, 0);
112-
final short blockLength = (short)header.blockLength();
113-
final short actingVersion = (short)header.version();
112+
final int blockLength = header.blockLength();
113+
final int actingVersion = header.version();
114114
final Object dto = decodeFrom.invoke(null,
115115
encodedMessage.buffer(), MessageHeaderDecoder.ENCODED_LENGTH, blockLength, actingVersion);
116116
outputBuffer.setMemory(0, outputBuffer.capacity(), (byte)0);

sbe-tool/src/test/java/uk/co/real_logic/sbe/generation/java/DtoTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ void shouldRoundTripCar2()
5656
final ExpandableArrayBuffer inputBuffer = new ExpandableArrayBuffer();
5757
final int inputLength = encodeCar(inputBuffer, 0);
5858

59-
final CarDto dto =
60-
CarDto.decodeFrom(inputBuffer, 0, (short)CarDecoder.BLOCK_LENGTH, (short)CarDecoder.SCHEMA_VERSION);
59+
final CarDto dto = CarDto.decodeFrom(inputBuffer, 0, CarDecoder.BLOCK_LENGTH, CarDecoder.SCHEMA_VERSION);
6160

6261
final ExpandableArrayBuffer outputBuffer = new ExpandableArrayBuffer();
6362
final int outputLength = CarDto.encodeWith(dto, outputBuffer, 0);

0 commit comments

Comments
 (0)