-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Keep the resource and property names in a compressed binary file
zstd level 15 was one of the fastest decompression algorithms, with the best compression ratio.
- Loading branch information
1 parent
a8ebbe4
commit d5d6f27
Showing
8 changed files
with
151 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 @@ | ||
include |
This file contains 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 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,9 @@ | ||
[options.package_data] | ||
mercury_engine_data_structures = | ||
*.bin | ||
|
||
[options.exclude_package_data] | ||
mercury_engine_data_structures = | ||
dread_property_names.json | ||
dread_resource_names.json | ||
sr_resource_names.json |
50 changes: 50 additions & 0 deletions
50
src/mercury_engine_data_structures/_dread_data_construct.py
This file contains 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,50 @@ | ||
import struct | ||
import typing | ||
|
||
import construct | ||
|
||
|
||
class CompressedZSTD(construct.Tunnel): | ||
def __init__(self, subcon, level: int = 3): | ||
super().__init__(subcon) | ||
import zstd | ||
self.lib = zstd | ||
self.level = level | ||
|
||
def _decode(self, data, context, path): | ||
return self.lib.decompress(data) | ||
|
||
def _encode(self, data, context, path): | ||
return self.lib.compress(data, self.level) | ||
|
||
|
||
class HashesDict(construct.Construct): | ||
def __init__(self): | ||
super().__init__() | ||
self._build_construct = construct.PrefixedArray( | ||
construct.Int32un, | ||
construct.Sequence( | ||
construct.PascalString(construct.Int16un, "ascii"), # key | ||
construct.Int64un, # hash | ||
) | ||
) | ||
|
||
def _parse(self, stream, context, path) -> typing.Dict[str, int]: | ||
key_size_struct = struct.Struct("=H") | ||
value_size_struct = struct.Struct("=Q") | ||
|
||
count = construct.Int32un._parse(stream, None, "") | ||
|
||
result = {} | ||
for _ in range(count): | ||
key = stream.read(key_size_struct.unpack(stream.read(2))[0]).decode() | ||
value = value_size_struct.unpack(stream.read(8))[0] | ||
result[key] = value | ||
|
||
return result | ||
|
||
def _build(self, obj: typing.Dict[str, int], stream, context, path): | ||
return self._build_construct._build(list(obj.items()), stream, context, path) | ||
|
||
|
||
KnownHashes = CompressedZSTD(HashesDict(), 15) |
This file contains 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 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 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