From 8ef3ef0ba5c08feac61d7f4911c1625f2767b9f9 Mon Sep 17 00:00:00 2001 From: Graham Date: Mon, 15 Jan 2024 22:17:53 +0000 Subject: [PATCH] Fix Js5MasterIndex creation if the LENGTHS format is used The groups field is populated with the group capacity, not the group size. (Thanks Ominious.) Update the test to cover this case, by adjusting the test index so its size and capacity are distinct. Signed-off-by: Graham --- .../kotlin/org/openrs2/cache/Js5MasterIndex.kt | 2 +- .../org/openrs2/cache/Js5MasterIndexTest.kt | 6 +++--- .../openrs2/cache/master-index/lengths/255/0.dat | Bin 85 -> 85 bytes 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cache/src/main/kotlin/org/openrs2/cache/Js5MasterIndex.kt b/cache/src/main/kotlin/org/openrs2/cache/Js5MasterIndex.kt index 50fa4534f8..e45333ac36 100644 --- a/cache/src/main/kotlin/org/openrs2/cache/Js5MasterIndex.kt +++ b/cache/src/main/kotlin/org/openrs2/cache/Js5MasterIndex.kt @@ -141,7 +141,7 @@ public data class Js5MasterIndex( } val version = index.version - val groups = index.size + val groups = index.capacity val totalUncompressedLength = index.sumOf(Js5Index.Group<*>::uncompressedLength) // TODO(gpe): should we throw an exception if there are trailing bytes here or in the block above? diff --git a/cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt b/cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt index 81b892782a..345b120e62 100644 --- a/cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt +++ b/cache/src/test/kotlin/org/openrs2/cache/Js5MasterIndexTest.kt @@ -114,9 +114,9 @@ class Js5MasterIndexTest { MasterIndexFormat.LENGTHS, mutableListOf( Js5MasterIndex.Entry( - 0x12345678, -1080883457, 3, 123, ByteBufUtil.decodeHexDump( - "0bf30b80b7213154ada5c3797be15a8fbb6a96a80432e2093e10617bcb4e67de" + - "9a858211cabe844c6fa3a1fbfe3164a3e4e1918983c69597dff3fc3c53096884" + 0x12345678, -817299640, 13, 123, ByteBufUtil.decodeHexDump( + "7c2eb43256e9350b637d0ca819813fa3397bc6035a72c6c7e41b714b74301c7e" + + "bba0e6b5408cb2514656181b75f2040397e4eb6944456ce60ca337a32a1c4f05" ) ) ) diff --git a/cache/src/test/resources/org/openrs2/cache/master-index/lengths/255/0.dat b/cache/src/test/resources/org/openrs2/cache/master-index/lengths/255/0.dat index f0f35870f4bb70caad891d010ca630ed9d05368b..e82d8170ca586bef5bdd2ccdc1c171351a02026c 100644 GIT binary patch delta 25 dcmWFy6=nc}05&0$unHCiW+0o9fqSB`696f!10eta delta 25 dcmWFy6=nc}05&0$unHCiW+0o9fpMa+696fM0~Y`Q