-
Notifications
You must be signed in to change notification settings - Fork 1
Cache writing/editing. #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ultraviolet-jordan
wants to merge
24
commits into
development
Choose a base branch
from
feature/writing
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
8787b83
Merge pull request #16 from runetopic/development
ultraviolet-jordan 50c7335
Merge pull request #17 from runetopic/development
ultraviolet-jordan 629635f
Merge pull request #18 from runetopic/development
ultraviolet-jordan 8fec609
Merge pull request #19 from runetopic/development
ultraviolet-jordan 47f99c8
Add start to cache writing and push branch.
ultraviolet-jordan 747c68e
Merge pull request #20 from runetopic/development
ultraviolet-jordan 7fa3b4b
Merge branch 'development' of github.com:xlite2/cache-lib into featur…
ultraviolet-jordan 5a832f0
Refactor some of the code for decoding/encoding the data to build an …
ultraviolet-jordan 02bb1c7
Merge pull request #22 from runetopic/development
ultraviolet-jordan d8f26e5
Add more testing for DatIndexSector.
ultraviolet-jordan 1c12077
Add more tests to DatIndexSector and more work to the encoding.
ultraviolet-jordan 7eca120
Update to Kotlin 1.5.31 and update README.md.
ultraviolet-jordan 9893df4
Removing dat file
ultraviolet-jordan a81c36a
Merging
ultraviolet-jordan 6623f6e
Update README.md
ultraviolet-jordan ae5ae4c
Fixing java version
tyler27 6cf4283
Merge branch 'main' of github.com:runetopic/cache-lib into feature/wr…
ultraviolet-jordan ccfd73a
Format.
ultraviolet-jordan e49e5b5
Cache and Loader code refactor.
ultraviolet-jordan d87da6f
Update README.md
tyler27 ea752f5
Update README.md
tyler27 14dbbce
Pulling README.md changes from master
tyler27 8731b24
Removing IInterface pattern
tyler27 9cd8c56
Fixing failing test
tyler27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
cache/src/main/kotlin/com/runetopic/cache/store/storage/js5/Js5IndexEncoder.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| package com.runetopic.cache.store.storage.js5 | ||
|
|
||
| import com.runetopic.cache.extension.Variable | ||
| import com.runetopic.cache.extension.putIntShortSmart | ||
| import com.runetopic.cache.hierarchy.index.Index | ||
| import java.nio.ByteBuffer | ||
|
|
||
| /** | ||
| * @author Jordan Abraham | ||
| */ | ||
| internal fun encode( | ||
| index: Index | ||
| ): ByteBuffer { | ||
| val header = ByteBuffer.allocate(if (index.protocol >= 7) 6 else 4) | ||
| header.put(index.protocol.toByte()) | ||
|
|
||
| val mask = 0x0 | ||
| if (index.isNamed) mask or 0x1 | ||
| if (index.isUsingWhirlpool) mask or 0x2 | ||
| header.put(mask.toByte()) | ||
|
|
||
| val count = index.groups().size | ||
| if (index.protocol >= 7) header.putIntShortSmart(count) else header.putShort(count.toShort()) | ||
|
|
||
| val stream = index.groups().stream() | ||
| val groupIds = stream.map { it.id }.toList().toIntArray() | ||
| val nameHashes = stream.map { it.nameHash }.toList().toIntArray() | ||
| val crcs = stream.map { it.crc }.toList().toIntArray() | ||
| val whirlpools = stream.map { it.whirlpool }.toList().toTypedArray() | ||
| val revisions = stream.map { it.revision }.toList().toIntArray() | ||
|
|
||
| val groupNameHashes = encodeGroupNameHashes(count, index.isNamed, groupIds, nameHashes) | ||
| val groupCrcs = encodeGroupCrcs(count, groupIds, crcs) | ||
| val groupWhirlpools = encodeGroupWhirlpools(count, groupIds, index.isUsingWhirlpool, whirlpools) | ||
| val groupRevisions = encodeGroupRevisions(count, groupIds, revisions) | ||
|
|
||
| val buffer = ByteBuffer.allocate(header.position() | ||
| + groupNameHashes.position() | ||
| + groupCrcs.position() | ||
| + groupWhirlpools.position() | ||
| + groupRevisions.position()) | ||
|
|
||
| buffer.put(header) | ||
| //TODO Group ids | ||
| buffer.put(groupNameHashes) | ||
| buffer.put(groupCrcs) | ||
| buffer.put(groupWhirlpools) | ||
| buffer.put(groupRevisions) | ||
| //TODO The rest | ||
| return buffer | ||
| } | ||
|
|
||
| fun encodeGroupFileIds( | ||
| count: Int, | ||
| groupIds: IntArray, | ||
| protocol: Int, | ||
| groupFileIds: IntArray | ||
| ): ByteBuffer { | ||
| var capacity = 0 | ||
| (0 until count).forEach { | ||
| capacity += Variable.asSizeBytes(protocol, groupFileIds[groupIds[it]]) | ||
| } | ||
| val buffer = ByteBuffer.allocate(capacity) | ||
| (0 until count).forEach { | ||
| if (protocol >= 7) buffer.putIntShortSmart(groupFileIds[groupIds[it]]) else buffer.putShort(groupFileIds[groupIds[it]].toShort()) | ||
| } | ||
| return buffer | ||
| } | ||
|
|
||
| fun encodeGroupRevisions( | ||
| count: Int, | ||
| groupIds: IntArray, | ||
| revisions: IntArray | ||
| ): ByteBuffer { | ||
| val buffer = ByteBuffer.allocate(count * Int.SIZE_BYTES) | ||
| (0 until count).forEach { | ||
| buffer.putInt(revisions[groupIds[it]]) | ||
| } | ||
| return buffer | ||
| } | ||
|
|
||
| fun encodeGroupWhirlpools( | ||
| count: Int, | ||
| groupIds: IntArray, | ||
| usesWhirlpool: Boolean, | ||
| whirlpools: Array<ByteArray> | ||
| ): ByteBuffer { | ||
| if ((usesWhirlpool.not())) return ByteBuffer.allocate(0) | ||
|
|
||
| val buffer = ByteBuffer.allocate(count * 64) | ||
| (0 until count).forEach { | ||
| buffer.put(whirlpools[groupIds[it]]) | ||
| } | ||
| return buffer | ||
| } | ||
|
|
||
| fun encodeGroupCrcs( | ||
| count: Int, | ||
| groupIds: IntArray, | ||
| crcs: IntArray | ||
| ): ByteBuffer { | ||
| val buffer = ByteBuffer.allocate(count * Int.SIZE_BYTES) | ||
| (0 until count).forEach { | ||
| buffer.putInt(crcs[groupIds[it]]) | ||
| } | ||
| return buffer | ||
| } | ||
|
|
||
| fun encodeGroupNameHashes( | ||
| count: Int, | ||
| isNamed: Boolean, | ||
| groupIds: IntArray, | ||
| nameHashes: IntArray | ||
| ): ByteBuffer { | ||
| if (isNamed.not()) return ByteBuffer.allocate(0) | ||
|
|
||
| val buffer = ByteBuffer.allocate(count * Int.SIZE_BYTES) | ||
| (0 until count).forEach { | ||
| buffer.putInt(nameHashes[groupIds[it]]) | ||
| } | ||
| return buffer | ||
| } | ||
|
|
||
| private fun encodeFileNameHashes( | ||
| count: Int, | ||
| groupIds: IntArray, | ||
| validFileIds: IntArray, | ||
| isNamed: Boolean, | ||
| fileNameHashes: Array<IntArray> | ||
| ): ByteBuffer { | ||
| if (isNamed.not()) return ByteBuffer.allocate(0) | ||
| //TODO Figure out a way to calc the number of bytes without doing it like this. | ||
| var bytes = 0 | ||
| (0 until count).forEach { | ||
| (0 until validFileIds[groupIds[it]]).forEach { _ -> | ||
| bytes += Int.SIZE_BYTES | ||
| } | ||
| } | ||
| val buffer = ByteBuffer.allocate(bytes) | ||
| (0 until count).forEach { | ||
| val groupId = groupIds[it] | ||
| (0 until validFileIds[groupId]).forEach { fileId -> | ||
| buffer.putInt(fileNameHashes[groupId][fileId]) | ||
| } | ||
| } | ||
| return buffer | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.