Track down (now obvious) signed comparison of tag value issue
This commit is contained in:
@ -13,7 +13,9 @@ import static nearenough.util.Preconditions.checkNotNull;
|
||||
|
||||
public final class RtMessageBuilder {
|
||||
|
||||
private final Map<RtTag, byte[]> map = new TreeMap<>(Comparator.comparing(RtTag::valueLE));
|
||||
private final Map<RtTag, byte[]> map = new TreeMap<>(
|
||||
Comparator.comparing(RtTag::valueLE, Integer::compareUnsigned)
|
||||
);
|
||||
|
||||
private ByteBufAllocator allocator = ByteBufAllocator.DEFAULT;
|
||||
private boolean shouldAddPadding = false;
|
||||
|
@ -78,14 +78,14 @@ public enum RtTag {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The on-the-wire representation of this tag.
|
||||
* @return The <b>unsigned</b> on-the-wire representation of this tag.
|
||||
*/
|
||||
public int wireEncoding() {
|
||||
return wireEncoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The little-endian representation of this tag.
|
||||
* @return The <b>unsigned</b> little-endian representation of this tag.
|
||||
*/
|
||||
public int valueLE() {
|
||||
return valueLE;
|
||||
|
@ -57,22 +57,26 @@ public final class RtMessageBuilderTest {
|
||||
byte[] value = {6, 7, 8, 9};
|
||||
|
||||
RtMessage msg = RtMessage.builder()
|
||||
.add(RtTag.INDX, value)
|
||||
.add(RtTag.NONC, value)
|
||||
.addPadding(true)
|
||||
.build();
|
||||
|
||||
assertThat(msg.numTags(), equalTo(2));
|
||||
assertArrayEquals(msg.get(RtTag.INDX), value);
|
||||
assertArrayEquals(msg.get(RtTag.NONC), value);
|
||||
|
||||
// 4 numTags
|
||||
// 4 single offset
|
||||
// 8 two tags (PAD and INDX)
|
||||
// 4 INDX value length
|
||||
// 8 two tags (NONC and PAD)
|
||||
// 4 NONC value length
|
||||
// --
|
||||
// 20 bytes
|
||||
//
|
||||
// 1024 - 20 = 1004 length of PAD value
|
||||
assertThat(msg.get(RtTag.PAD).length, equalTo(1004));
|
||||
|
||||
ArrayList<RtTag> tags = new ArrayList<>(msg.mapping().keySet());
|
||||
assertThat(tags.get(0), equalTo(RtTag.NONC));
|
||||
assertThat(tags.get(1), equalTo(RtTag.PAD));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user