rrb-common 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e1063be8d2fdedff9c18342214732a264e406aaf0e9f88bc3a699f3ff8a85cd
4
- data.tar.gz: ebd87f1f93863dc31cc24dba6b9bd26c01aa79b263cc160c0d02bd60d461c236
3
+ metadata.gz: 25249c7b5e3aa642c23637cc4e3bad8ce62434a1d77962287fe7cab331d016c9
4
+ data.tar.gz: 7592bacd9ddfb0d7371bfd24f87a84de502e2500f7a81a5ca3f8bbd5f1d888a5
5
5
  SHA512:
6
- metadata.gz: d4b29deb98f9c99c8b8af84c29b8e6c06fe30bf37810c768f4de3b5d9d74ec1af89e99d78e3dab9270a19c25d20d5da558b3b5afa996d2c4c26464d094eb77f7
7
- data.tar.gz: 181a1537c93ea4708e755ac9976e9d5f3eea02c6a97854e0491538a84a52262382fc23f7e9aed59922721bbcb9c74960231fcb48a6dc486e83655ce0840344ff
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 :ISAAC, 'rune/core/isaac'
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'
@@ -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(signed:, mutation:, order:)
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.flip
57
+ @data.reverse!
58
58
  value = amount.times.each_with_object([]) { value << read_byte(signed: false, mutation:) }
59
- @data.flip
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
- directive = signed ? 'c' : 'C'
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
- directive << case order
80
- when :BIG then '>'
81
- when :LITTLE then '<'
82
- else ''
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(signed: false, mutation: :STD, order: :BIG)
93
- unpacked = @data.slice!(0..2).unpack('C3')
89
+ def read_int24(mutation: :STD, order: :BIG)
90
+ value = 0
94
91
  case order
95
92
  when :BIG
96
- if signed
97
- value = (unpacked[0] << 16) | (unpacked[1] << 8) | unpacked[2]
98
- unpacked[0] & 0x80 != 0 ? value - 0x10000 : value
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
- if signed
111
- value = (unpacked[2] << 16) | (unpacked[1] << 8) | unpacked[0]
112
- unpacked[0] & 0x80 != 0 ? value - 0x10000 : value
113
- else
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
- when :BIG
149
- directive = signed ? 'q>' : 'Q>'
150
- value = @data.slice!(0..7).unpack1(directive)
151
- mutate(value, mutation)
152
- when :LITTLE
153
- directive = signed ? 'q<' : 'Q<'
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}
@@ -1,6 +1,6 @@
1
1
  module RuneRb::Core
2
2
  # An implementation of an ISAAC cipher used to generate random numbers for message interchange.
3
- class ISAAC
3
+ class RubyISAAC
4
4
  using RuneRb::Patches::IntegerRefinements
5
5
 
6
6
  # Called when a new ISAAC Cipher is created.
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.5
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-13 00:00:00.000000000 Z
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