Skip to content

Commit

Permalink
Merge pull request #290 from LossyDragon/kv-alt-end
Browse files Browse the repository at this point in the history
Add KV alternate end and basic test.
  • Loading branch information
LossyDragon authored Oct 16, 2024
2 parents 71eb8f9 + 625c8d2 commit 46aa2f7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/java/in/dragonbra/javasteam/types/KeyValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ private static boolean tryReadAsBinaryCore(InputStream is, KeyValue current, Key
while (true) {
Type type = Type.from(br.readByte());

if (type == Type.END) {
if (type == Type.END || type == Type.ALTERNATEEND) {
break;
}

Expand Down Expand Up @@ -685,7 +685,8 @@ public enum Type {
COLOR((byte) 6),
UINT64((byte) 7),
END((byte) 8),
INT64((byte) 10);
INT64((byte) 10),
ALTERNATEEND((byte) 11);

private final byte code;

Expand Down
21 changes: 21 additions & 0 deletions src/test/java/in/dragonbra/javasteam/types/KeyValueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,27 @@ public void decodesBinaryWithFieldType10() {
Assertions.assertEquals(0x0807060504030201L, kv.get("key").asLong());
}

@Test
public void decodesBinaryWithAlternateEnd() {
var hex = "00546573744F626A656374000A6B65790001020304050607080B0B";
byte[] binary = null;
try {
binary = Hex.decodeHex(hex);
} catch (DecoderException e) {
Assertions.fail(e);
}
var kv = new KeyValue();

try (var ms = new MemoryStream(binary)) {
var read = kv.tryReadAsBinary(ms);
Assertions.assertTrue(read);
} catch (IOException e) {
Assertions.fail(e);
}

Assertions.assertEquals(0x0807060504030201L, kv.get("key").asLong());
}

@Test
public void keyValuesHandlesEnum() {
KeyValue kv = KeyValue.loadFromString("" +
Expand Down

0 comments on commit 46aa2f7

Please sign in to comment.