rrb-common 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rune/common.rb +2 -1
- data/lib/rune/core/constants.rb +7 -0
- data/lib/rune/core/readable_buffer.rb +28 -47
- data/lib/rune/core/{isaac.rb → ruby_isaac.rb} +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25249c7b5e3aa642c23637cc4e3bad8ce62434a1d77962287fe7cab331d016c9
|
4
|
+
data.tar.gz: 7592bacd9ddfb0d7371bfd24f87a84de502e2500f7a81a5ca3f8bbd5f1d888a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58a9a9da24f64061478f46982beb434b6a3e917c494bf36e437b50570593b2b05bb9870ad50bee4fb08cb82bfec4eb90e8377cae5504e513584582ce1030b6bf
|
7
|
+
data.tar.gz: b4810f557135b53ba88e89850d59076f24650df965ec0b497868ec41d7a47e8d47c635c6b5797c5297d994446335a479e1dad3c0f22da04c810503a571af8460
|
data/lib/rune/common.rb
CHANGED
@@ -19,7 +19,8 @@ module RuneRb
|
|
19
19
|
autoload :Buffer, 'rune/core/buffer'
|
20
20
|
autoload :Constants, 'rune/core/constants'
|
21
21
|
autoload :Identifiable, 'rune/core/identifiable'
|
22
|
-
autoload :
|
22
|
+
autoload :JavaISAAC, 'rune/core/java_isaac'
|
23
|
+
autoload :RubyISAAC, 'rune/core/ruby_isaac'
|
23
24
|
autoload :Logging, 'rune/core/logging'
|
24
25
|
autoload :ReadableBuffer, 'rune/core/readable_buffer'
|
25
26
|
autoload :Unit, 'rune/core/unit'
|
data/lib/rune/core/constants.rb
CHANGED
@@ -34,4 +34,11 @@ module RuneRb::Core::Constants
|
|
34
34
|
# The size of a chunk of data
|
35
35
|
# @return [Integer]
|
36
36
|
DATA_SIZE = DATA_BLOCK_SIZE + DATA_HEADER_SIZE
|
37
|
+
|
38
|
+
# The possible byte orders for reading/writing 24-bit integers. The integers will only be written in big or middle endian byte order.
|
39
|
+
# @return [Hash<Symbol, Array<Integer>>]
|
40
|
+
INT24_BYTE_ORDERS = {
|
41
|
+
BIG: [0, 1, 2].freeze,
|
42
|
+
LITTLE: [2, 1, 0].freeze
|
43
|
+
}.freeze
|
37
44
|
end
|
@@ -16,11 +16,10 @@ module RuneRb::Core::ReadableBuffer
|
|
16
16
|
# @param mutation [Symbol] an option mutation to apply to the read value.
|
17
17
|
def read(type: :byte, signed: false, mutation: :STD, order: :BIG, options: nil)
|
18
18
|
case type
|
19
|
-
when :bits then read_bits(options[:amount])
|
20
19
|
when :byte then read_byte(signed:, mutation:)
|
21
20
|
when :bytes then read_bytes(options[:amount] || 1, mutation:)
|
22
21
|
when :short then read_short(signed:, mutation:, order:)
|
23
|
-
when :int24 then read_int24(
|
22
|
+
when :int24 then read_int24(mutation:, order:)
|
24
23
|
when :int then read_int(signed:, mutation:, order:)
|
25
24
|
when :long then read_long(signed:, mutation:, order:)
|
26
25
|
when :smart then read_smart(signed:, mutation:)
|
@@ -51,12 +50,13 @@ module RuneRb::Core::ReadableBuffer
|
|
51
50
|
end
|
52
51
|
|
53
52
|
# Probably did this wrong
|
53
|
+
# @todo fix and test
|
54
54
|
# @param amount [Integer] the amount of bytes to read
|
55
55
|
# @param mutation [Symbol] an optional mutation to apply to the result.
|
56
56
|
def read_bytes_reverse(amount, mutation)
|
57
|
-
@data.
|
57
|
+
@data.reverse!
|
58
58
|
value = amount.times.each_with_object([]) { value << read_byte(signed: false, mutation:) }
|
59
|
-
@data.
|
59
|
+
@data.reverse!
|
60
60
|
value
|
61
61
|
end
|
62
62
|
|
@@ -65,8 +65,7 @@ module RuneRb::Core::ReadableBuffer
|
|
65
65
|
# @param mutation [Symbol] mutation that should be applied to the byte value.
|
66
66
|
# @return [Integer] the read byte value.
|
67
67
|
def read_byte(mutation: :STD, signed: false)
|
68
|
-
|
69
|
-
value = @data.slice!(0).unpack1(directive)
|
68
|
+
value = @data.slice!(0).unpack1(signed ? 'c' : 'C')
|
70
69
|
mutate(value, mutation)
|
71
70
|
end
|
72
71
|
|
@@ -75,46 +74,32 @@ module RuneRb::Core::ReadableBuffer
|
|
75
74
|
# @param mutation [String] mutation that should be applied to the short value
|
76
75
|
# @param order [Symbol] they byte order to read the short value
|
77
76
|
def read_short(signed: false, mutation: :STD, order: :BIG)
|
78
|
-
directive = "#{signed ? 's' : 'S'}
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
77
|
+
directive = "#{signed ? 's' : 'S'}#{case order
|
78
|
+
when :BIG then '>'
|
79
|
+
when :LITTLE then '<'
|
80
|
+
else ''
|
81
|
+
end}"
|
84
82
|
value = @data.slice!(0..1).unpack1(directive)
|
85
83
|
mutate(value, mutation)
|
86
84
|
end
|
87
85
|
|
88
|
-
# Reads a 24-Bit Integer value from the {Buffer#data}
|
89
|
-
# @param signed [Boolean] should the value be signed.
|
86
|
+
# Reads a 24-Bit Unsigned Integer value from the {Buffer#data}
|
90
87
|
# @param mutation [Symbol] mutation that should be applied to the value
|
91
88
|
# @param order [String] they byte order to read the value
|
92
|
-
def read_int24(
|
93
|
-
|
89
|
+
def read_int24(mutation: :STD, order: :BIG)
|
90
|
+
value = 0
|
94
91
|
case order
|
95
92
|
when :BIG
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
else
|
100
|
-
(unpacked[0] << 16) | (unpacked[1] << 8) | unpacked[2]
|
101
|
-
end
|
102
|
-
when :MIDDLE
|
103
|
-
if signed
|
104
|
-
value = (unpacked[1] << 16) | (unpacked[2] << 8) | unpacked[0]
|
105
|
-
unpacked[1] & 0x80 != 0 ? value - 0x10000 : value
|
106
|
-
else
|
107
|
-
(unpacked[1] << 16) | (unpacked[2] << 8) | unpacked[0]
|
108
|
-
end
|
93
|
+
value |= read_byte << 16
|
94
|
+
value |= read_byte << 8
|
95
|
+
value |= read_byte(mutation:)
|
109
96
|
when :LITTLE
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
(unpacked[2] << 16) | (unpacked[1] << 8) | unpacked[0]
|
115
|
-
end
|
116
|
-
else read_int24(signed:, mutation:, order: :BIG)
|
97
|
+
value |= read_byte(mutation:)
|
98
|
+
value |= read_byte << 8
|
99
|
+
value |= read_byte << 16
|
100
|
+
else read_int24(mutation:, order: :BIG)
|
117
101
|
end
|
102
|
+
value
|
118
103
|
end
|
119
104
|
|
120
105
|
# Reads a integer value from the {Buffer#data}
|
@@ -144,17 +129,13 @@ module RuneRb::Core::ReadableBuffer
|
|
144
129
|
# @param mutation [Symbol] mutation that should be applied to the long value
|
145
130
|
# @param order [String] they byte order to read the long value
|
146
131
|
def read_long(signed: false, mutation: :STD, order: :BIG)
|
147
|
-
case order
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
value = @data.slice!(0..7).unpack1(directive)
|
155
|
-
mutate(value, mutation)
|
156
|
-
else read_long(signed:, mutation:, order: :BIG)
|
157
|
-
end
|
132
|
+
directive = "#{signed ? 'q' : 'Q'}#{case order
|
133
|
+
when :BIG then '>'
|
134
|
+
when :LITTLE then '<'
|
135
|
+
else ''
|
136
|
+
end}"
|
137
|
+
value = @data.slice!(0..7).unpack1(directive)
|
138
|
+
mutate(value, mutation)
|
158
139
|
end
|
159
140
|
|
160
141
|
# Read a smart value from the {Buffer#data}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rrb-common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick W.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -161,9 +161,9 @@ files:
|
|
161
161
|
- lib/rune/core/buffer.rb
|
162
162
|
- lib/rune/core/constants.rb
|
163
163
|
- lib/rune/core/identifiable.rb
|
164
|
-
- lib/rune/core/isaac.rb
|
165
164
|
- lib/rune/core/logging.rb
|
166
165
|
- lib/rune/core/readable_buffer.rb
|
166
|
+
- lib/rune/core/ruby_isaac.rb
|
167
167
|
- lib/rune/core/unit.rb
|
168
168
|
- lib/rune/core/writeable_buffer.rb
|
169
169
|
- lib/rune/patches/integer_refinements.rb
|