bin_struct 0.5.1 → 0.5.3
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/CHANGELOG.md +21 -0
- data/README.md +2 -2
- data/lib/bin_struct/abstract_tlv.rb +40 -17
- data/lib/bin_struct/array.rb +47 -17
- data/lib/bin_struct/bit_attr.rb +42 -29
- data/lib/bin_struct/cstring.rb +16 -13
- data/lib/bin_struct/enum.rb +10 -10
- data/lib/bin_struct/int.rb +32 -30
- data/lib/bin_struct/int_string.rb +14 -13
- data/lib/bin_struct/length_from.rb +3 -3
- data/lib/bin_struct/oui.rb +2 -2
- data/lib/bin_struct/string.rb +7 -6
- data/lib/bin_struct/struct.rb +123 -78
- data/lib/bin_struct/structable.rb +2 -2
- data/lib/bin_struct/version.rb +2 -2
- data/lib/bin_struct.rb +2 -2
- metadata +9 -8
data/lib/bin_struct/struct.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# This file is part of BinStruct
|
|
4
|
-
# see https://
|
|
4
|
+
# see https://codeberg.org/lemontree55/bin_struct for more informations
|
|
5
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
|
6
6
|
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
|
7
7
|
# This program is published under MIT license.
|
|
@@ -115,15 +115,17 @@ module BinStruct
|
|
|
115
115
|
FMT_ATTR = "%14s %16s: %s\n"
|
|
116
116
|
|
|
117
117
|
class << self
|
|
118
|
+
# @private
|
|
118
119
|
# Get attribute definitions for this class.
|
|
119
|
-
# @return [Hash]
|
|
120
|
+
# @return [Hash{Symbol=>StructDef}]
|
|
120
121
|
attr_reader :attr_defs
|
|
122
|
+
# @private
|
|
121
123
|
# Get bit attribute defintions for this class
|
|
122
|
-
# @return [Hash{Symbol=>Array
|
|
124
|
+
# @return [Hash{Symbol=>Array<Symbol>}]
|
|
123
125
|
attr_reader :bit_attrs
|
|
124
126
|
|
|
125
127
|
# On inheritage, create +@attr_defs+ class variable
|
|
126
|
-
# @param [Class]
|
|
128
|
+
# @param klass [Class]
|
|
127
129
|
# @return [void]
|
|
128
130
|
def inherited(klass)
|
|
129
131
|
super
|
|
@@ -149,6 +151,27 @@ module BinStruct
|
|
|
149
151
|
end
|
|
150
152
|
|
|
151
153
|
# Define an attribute in class
|
|
154
|
+
# @param name [Symbol] name of the attribute to define
|
|
155
|
+
# @param type [Structable] class or instance
|
|
156
|
+
# +:builder+ option is not set.
|
|
157
|
+
# @!macro [new] x_attr_options
|
|
158
|
+
# @param options [Hash{Symbol=>Object}] Unrecognized options are passed to object builder if
|
|
159
|
+
# @option options [Object] :default default value. May be a proc. This lambda
|
|
160
|
+
# take one argument: the caller object.
|
|
161
|
+
# @option options [Lambda] :builder lambda to construct this attribute.
|
|
162
|
+
# Parameters to this lambda is the caller object and the attribute type class.
|
|
163
|
+
# @option options [Lambda] :optional define this attribute as optional. Given lambda
|
|
164
|
+
# is used to known if this attribute is present or not. Parameter to this lambda is
|
|
165
|
+
# the being defined Struct object.
|
|
166
|
+
# @!macro x_attr_options
|
|
167
|
+
# @return [void]
|
|
168
|
+
# @example
|
|
169
|
+
# class MyClass < BinStruct::Struct
|
|
170
|
+
# def initialize(parent, options={})
|
|
171
|
+
# super(options)
|
|
172
|
+
# @parent = parent
|
|
173
|
+
# end
|
|
174
|
+
# end
|
|
152
175
|
# class BinaryStruct < BinStruct::Struct
|
|
153
176
|
# # 8-bit value
|
|
154
177
|
# define_attr :value1, BinStruct::Int8
|
|
@@ -159,20 +182,9 @@ module BinStruct
|
|
|
159
182
|
# end
|
|
160
183
|
#
|
|
161
184
|
# bs = BinaryStruct.new
|
|
162
|
-
# bs[value1] # => BinStruct::Int8
|
|
163
|
-
# bs.value1
|
|
164
|
-
#
|
|
165
|
-
# @param [Structable] type class or instance
|
|
166
|
-
# @param [Hash] options Unrecognized options are passed to object builder if
|
|
167
|
-
# +:builder+ option is not set.
|
|
168
|
-
# @option options [Object] :default default value. May be a proc. This lambda
|
|
169
|
-
# take one argument: the caller object.
|
|
170
|
-
# @option options [Lambda] :builder lambda to construct this attribute.
|
|
171
|
-
# Parameters to this lambda is the caller object and the attribute type class.
|
|
172
|
-
# @option options [Lambda] :optional define this attribute as optional. Given lambda
|
|
173
|
-
# is used to known if this attribute is present or not. Parameter to this lambda is
|
|
174
|
-
# the being defined Struct object.
|
|
175
|
-
# @return [void]
|
|
185
|
+
# bs[:value1].class # => BinStruct::Int8
|
|
186
|
+
# bs.value1.class # => Integer
|
|
187
|
+
# bs.value1 # => 0
|
|
176
188
|
def define_attr(name, type, options = {})
|
|
177
189
|
attributes << name
|
|
178
190
|
attr_defs[name] = StructDef.new(type,
|
|
@@ -185,11 +197,11 @@ module BinStruct
|
|
|
185
197
|
end
|
|
186
198
|
|
|
187
199
|
# Define a attribute, before another one
|
|
188
|
-
# @param [Symbol,nil]
|
|
200
|
+
# @param other [Symbol,nil] attribute name to create a new one before. If +nil+,
|
|
189
201
|
# new attribute is appended.
|
|
190
|
-
# @param [Symbol]
|
|
191
|
-
# @param [Structable]
|
|
192
|
-
#
|
|
202
|
+
# @param name [Symbol] attribute name to create
|
|
203
|
+
# @param type [Structable] class or instance
|
|
204
|
+
# @!macro x_attr_options
|
|
193
205
|
# @return [void]
|
|
194
206
|
# @see .define_attr
|
|
195
207
|
def define_attr_before(other, name, type, options = {})
|
|
@@ -200,11 +212,11 @@ module BinStruct
|
|
|
200
212
|
end
|
|
201
213
|
|
|
202
214
|
# Define an attribute, after another one
|
|
203
|
-
# @param [Symbol,nil]
|
|
215
|
+
# @param other [Symbol,nil] attribute name to create a new one after. If +nil+,
|
|
204
216
|
# new attribute is appended.
|
|
205
|
-
# @param [Symbol]
|
|
206
|
-
# @param [Structable]
|
|
207
|
-
#
|
|
217
|
+
# @param name [Symbol] attribute name to create
|
|
218
|
+
# @param type [Structable] class or instance
|
|
219
|
+
# @!macro x_attr_options
|
|
208
220
|
# @return [void]
|
|
209
221
|
# @see .define_attr
|
|
210
222
|
def define_attr_after(other, name, type, options = {})
|
|
@@ -215,7 +227,7 @@ module BinStruct
|
|
|
215
227
|
end
|
|
216
228
|
|
|
217
229
|
# Remove a previously defined attribute
|
|
218
|
-
# @param [Symbol]
|
|
230
|
+
# @param name [Symbol]
|
|
219
231
|
# @return [void]
|
|
220
232
|
def remove_attr(name)
|
|
221
233
|
attributes.delete(name)
|
|
@@ -228,8 +240,8 @@ module BinStruct
|
|
|
228
240
|
end
|
|
229
241
|
|
|
230
242
|
# Update a previously defined attribute
|
|
231
|
-
# @param [Symbol]
|
|
232
|
-
#
|
|
243
|
+
# @param name [Symbol] attribute name to create
|
|
244
|
+
# @!macro x_attr_options
|
|
233
245
|
# @return [void]
|
|
234
246
|
# @see .define_attr
|
|
235
247
|
# @raise [ArgumentError] unknown attribute
|
|
@@ -243,13 +255,7 @@ module BinStruct
|
|
|
243
255
|
attr_defs[name].options.merge!(options)
|
|
244
256
|
end
|
|
245
257
|
|
|
246
|
-
# Define a bit attribute
|
|
247
|
-
# class MyHeader < BinStruct::Struct
|
|
248
|
-
# # define a 16-bit attribute named :flag
|
|
249
|
-
# # flag1, flag2 and flag3 are 1-bit attributes
|
|
250
|
-
# # type and stype are 3-bit attributes, reserved is a 7-bit attribute
|
|
251
|
-
# define_bit_attr :flags, flag1: 1, flag2: 1, flag3: 1, type: 3, stype: 3, reserved: 7
|
|
252
|
-
# end
|
|
258
|
+
# Define a bit attribute.
|
|
253
259
|
# A bit attribute of size 1 bit defines 3 methods:
|
|
254
260
|
# * +#attr+ which returns an Integer,
|
|
255
261
|
# * +#attr?+ which returns a Boolean,
|
|
@@ -257,12 +263,21 @@ module BinStruct
|
|
|
257
263
|
# A bit attribute of more bits defines only 2 methods:
|
|
258
264
|
# * +#attr+ which returns an Integer,
|
|
259
265
|
# * +#attr=+ which takes an Integer.
|
|
260
|
-
# @param [Symbol]
|
|
261
|
-
# @param [
|
|
262
|
-
# @param [Integer] default
|
|
263
|
-
# @param [Hash{Symbol=>Integer}]
|
|
266
|
+
# @param attr [Symbol] attribute name
|
|
267
|
+
# @param endian [Symbol] endianess of Integer (:big, :little or :native)
|
|
268
|
+
# @param default [Integer] default value for whole attribute
|
|
269
|
+
# @param fields [Hash{Symbol=>Integer}] Hash defining fields. Keys are field names, values are field sizes.
|
|
264
270
|
# @return [void]
|
|
265
271
|
# @since 0.3.0
|
|
272
|
+
# @example
|
|
273
|
+
# class MyHeader < BinStruct::Struct
|
|
274
|
+
# # define a 16-bit attribute named :flag
|
|
275
|
+
# # flag1, flag2 and flag3 are 1-bit attributes
|
|
276
|
+
# # type and stype are 3-bit attributes, reserved is a 7-bit attribute
|
|
277
|
+
# define_bit_attr :flags, flag1: 1, flag2: 1, flag3: 1, type: 3, stype: 3, reserved: 7
|
|
278
|
+
# end
|
|
279
|
+
# my_header = MyHeader.new(flag1: true)
|
|
280
|
+
# my_header.flags #=> 0x8000
|
|
266
281
|
def define_bit_attr(attr, endian: :big, default: 0, **fields)
|
|
267
282
|
width = fields.reduce(0) { |acc, ary| acc + ary.last }
|
|
268
283
|
bit_attr_klass = BitAttr.create(width: width, endian: endian, **fields)
|
|
@@ -280,11 +295,11 @@ module BinStruct
|
|
|
280
295
|
end
|
|
281
296
|
|
|
282
297
|
# Define a bit attribute, before another attribute
|
|
283
|
-
# @param [Symbol,nil]
|
|
298
|
+
# @param other [Symbol,nil] attribute name to create a new one before.
|
|
284
299
|
# If +nil+, new attribute is appended.
|
|
285
|
-
# @param [Symbol]
|
|
286
|
-
# @param [
|
|
287
|
-
# @param [Hash{Symbol=>Integer}]
|
|
300
|
+
# @param name [Symbol] attribute name to create
|
|
301
|
+
# @param endian [Symbol] endianess of Integer (:big, :little or :native)
|
|
302
|
+
# @param fields [Hash{Symbol=>Integer}] Hash defining fields. Keys are field names, values are field sizes.
|
|
288
303
|
# @return [void]
|
|
289
304
|
# @since 0.3.0
|
|
290
305
|
# @see .define_bit_attr
|
|
@@ -296,11 +311,11 @@ module BinStruct
|
|
|
296
311
|
end
|
|
297
312
|
|
|
298
313
|
# Define a bit attribute after another attribute
|
|
299
|
-
# @param [Symbol,nil]
|
|
314
|
+
# @param other [Symbol,nil] attribute name to create a new one after.
|
|
300
315
|
# If +nil+, new attribute is appended.
|
|
301
|
-
# @param [Symbol]
|
|
302
|
-
# @param [
|
|
303
|
-
# @param [Hash{Symbol=>Integer}]
|
|
316
|
+
# @param name [Symbol] attribute name to create
|
|
317
|
+
# @param endian [Symbol] endianess of Integer (:big, :little or :native)
|
|
318
|
+
# @param fields [Hash{Symbol=>Integer}] Hash defining fields. Keys are field names, values are field sizes.
|
|
304
319
|
# @return [void]
|
|
305
320
|
# @since 0.3.0
|
|
306
321
|
# @see .define_bit_attr
|
|
@@ -313,9 +328,9 @@ module BinStruct
|
|
|
313
328
|
|
|
314
329
|
private
|
|
315
330
|
|
|
316
|
-
# @param [Symbol]
|
|
317
|
-
# @param [Symbol,nil]
|
|
318
|
-
# @param [Symbol,nil]
|
|
331
|
+
# @param name [Symbol]
|
|
332
|
+
# @param before [Symbol,nil]
|
|
333
|
+
# @param after [Symbol,nil]
|
|
319
334
|
# @return [void]
|
|
320
335
|
# @raise [ArgumentError] Both +before+ and +after+ are nil, or both are set.
|
|
321
336
|
def move_attr(name, before: nil, after: nil)
|
|
@@ -330,11 +345,19 @@ module BinStruct
|
|
|
330
345
|
attributes[idx, 0] = name
|
|
331
346
|
end
|
|
332
347
|
|
|
348
|
+
# @param before [Symbol,nil]
|
|
349
|
+
# @param after [Symbol,nil]
|
|
350
|
+
# @return [void]
|
|
351
|
+
# @raise [ArgumentError] +before+ and +after+ are both nil or set
|
|
333
352
|
def move_check_destination(before, after)
|
|
334
353
|
raise ArgumentError 'one of before: and after: arguments MUST be set' if before.nil? && after.nil?
|
|
335
354
|
raise ArgumentError 'only one of before and after argument MUST be set' if !before.nil? && !after.nil?
|
|
336
355
|
end
|
|
337
356
|
|
|
357
|
+
# Generate Ruby code to define +name+ accessor
|
|
358
|
+
# @param name [Symbol]
|
|
359
|
+
# @param type [Class]
|
|
360
|
+
# @return [Array<String>]
|
|
338
361
|
def add_methods(name, type)
|
|
339
362
|
define = []
|
|
340
363
|
if type < Enum
|
|
@@ -349,28 +372,40 @@ module BinStruct
|
|
|
349
372
|
'end'
|
|
350
373
|
end
|
|
351
374
|
|
|
352
|
-
define.delete_at(1) if
|
|
353
|
-
define.delete_at(0) if
|
|
375
|
+
define.delete_at(1) if method_defined?(:"#{name}=")
|
|
376
|
+
define.delete_at(0) if method_defined?(name)
|
|
354
377
|
class_eval define.join("\n")
|
|
355
378
|
end
|
|
356
379
|
|
|
380
|
+
# Define a bit attribute on +self+
|
|
381
|
+
# @param attr [Symbol]
|
|
382
|
+
# @param field [Hash{Symbol=>Integer}]
|
|
383
|
+
# @return [void]
|
|
357
384
|
def register_bit_attr_field(attr, field)
|
|
358
385
|
bit_attrs[attr] ||= []
|
|
359
386
|
bit_attrs[attr] << field
|
|
360
387
|
end
|
|
361
388
|
|
|
389
|
+
# Add a property on given +attr+ from +options+
|
|
390
|
+
# @param attr [Symbol]
|
|
391
|
+
# @param property [Symbol] :default, :builder or :optional
|
|
392
|
+
# @!macro x_attr_options
|
|
393
|
+
# @return [void]
|
|
362
394
|
def attr_defs_property_from(attr, property, options)
|
|
363
395
|
attr_defs[attr].send(:"#{property}=", options.delete(property)) if options.key?(property)
|
|
364
396
|
end
|
|
365
397
|
|
|
398
|
+
# @param attr [Symbol]
|
|
399
|
+
# @return [void]
|
|
400
|
+
# @raise [ArgumentError] +attr+ is unknown
|
|
366
401
|
def check_existence_of(attr)
|
|
367
402
|
raise ArgumentError, "unknown #{attr} attribute for #{self}" unless attr_defs.key?(attr)
|
|
368
403
|
end
|
|
369
404
|
end
|
|
370
405
|
|
|
371
406
|
# Create a new Struct object
|
|
372
|
-
# @param [Hash]
|
|
373
|
-
# attributes, as
|
|
407
|
+
# @param options [Hash{Symbol=>Object}] Keys are attributes names, as defined by {.define_attr} and by
|
|
408
|
+
# {.define_bit_attr}. Values are values to set to attributes, as Ruby values (i.e Integer, String, etc...)
|
|
374
409
|
def initialize(options = {})
|
|
375
410
|
@attributes = {}
|
|
376
411
|
@optional_attributes = {}
|
|
@@ -389,22 +424,22 @@ module BinStruct
|
|
|
389
424
|
end
|
|
390
425
|
|
|
391
426
|
# Get attribute object
|
|
392
|
-
# @param [Symbol]
|
|
427
|
+
# @param attr [Symbol] attribute name
|
|
393
428
|
# @return [Structable]
|
|
394
429
|
def [](attr)
|
|
395
430
|
@attributes[attr]
|
|
396
431
|
end
|
|
397
432
|
|
|
398
433
|
# Set attribute object
|
|
399
|
-
# @param [Symbol]
|
|
400
|
-
# @param [Object]
|
|
434
|
+
# @param attr [Symbol] attribute name
|
|
435
|
+
# @param obj [Object]
|
|
401
436
|
# @return [Object]
|
|
402
437
|
def []=(attr, obj)
|
|
403
438
|
@attributes[attr] = obj
|
|
404
439
|
end
|
|
405
440
|
|
|
406
441
|
# Say if struct has given attribute
|
|
407
|
-
# @param [Symbol]
|
|
442
|
+
# @param attr [Symbol] attribute name
|
|
408
443
|
# @return [Boolean]
|
|
409
444
|
# @since 0.4.0
|
|
410
445
|
# @author LemonTree55
|
|
@@ -425,13 +460,14 @@ module BinStruct
|
|
|
425
460
|
end
|
|
426
461
|
|
|
427
462
|
# Say if this attribue is optional
|
|
428
|
-
# @param [Symbol]
|
|
463
|
+
# @param attr [Symbol] attribute name
|
|
429
464
|
# @return [Boolean]
|
|
430
465
|
def optional?(attr)
|
|
431
466
|
@optional_attributes.key?(attr)
|
|
432
467
|
end
|
|
433
468
|
|
|
434
469
|
# Say if an optional attribute is present
|
|
470
|
+
# @param attr [Symbol]
|
|
435
471
|
# @return [Boolean]
|
|
436
472
|
def present?(attr)
|
|
437
473
|
return true unless optional?(attr)
|
|
@@ -440,16 +476,17 @@ module BinStruct
|
|
|
440
476
|
end
|
|
441
477
|
|
|
442
478
|
# Populate object from a binary string
|
|
443
|
-
# @param [String]
|
|
479
|
+
# @param str [String]
|
|
444
480
|
# @return [Struct] self
|
|
445
481
|
def read(str)
|
|
446
482
|
return self if str.nil?
|
|
447
483
|
|
|
448
484
|
start = 0
|
|
485
|
+
str = str.b
|
|
449
486
|
attributes.each do |attr|
|
|
450
487
|
next unless present?(attr)
|
|
451
488
|
|
|
452
|
-
obj = self[attr].read(str
|
|
489
|
+
obj = self[attr].read(str[start..])
|
|
453
490
|
start += self[attr].sz
|
|
454
491
|
self[attr] = obj unless obj == self[attr]
|
|
455
492
|
end
|
|
@@ -491,13 +528,13 @@ module BinStruct
|
|
|
491
528
|
end
|
|
492
529
|
|
|
493
530
|
# Return object as a hash
|
|
494
|
-
# @return [Hash] keys: attributes, values: attribute values
|
|
531
|
+
# @return [Hash] keys: attributes, values: attribute human values
|
|
495
532
|
def to_h
|
|
496
533
|
attributes.to_h { |attr| [attr, @attributes[attr].to_human] }
|
|
497
534
|
end
|
|
498
535
|
|
|
499
536
|
# Get offset of given attribute in {Struct}.
|
|
500
|
-
# @param [Symbol]
|
|
537
|
+
# @param attr [Symbol] attribute name
|
|
501
538
|
# @return [Integer]
|
|
502
539
|
# @raise [ArgumentError] unknown attribute
|
|
503
540
|
def offset_of(attr)
|
|
@@ -513,7 +550,7 @@ module BinStruct
|
|
|
513
550
|
end
|
|
514
551
|
|
|
515
552
|
# Get bit attributes definition for given attribute.
|
|
516
|
-
# @param [Symbol]
|
|
553
|
+
# @param attr [Symbol] attribute defining bit attributes
|
|
517
554
|
# @return [Hash,nil] keys: bit attributes, values: their size in bits
|
|
518
555
|
def bits_on(attr)
|
|
519
556
|
self.class.bit_attrs[attr]
|
|
@@ -521,33 +558,37 @@ module BinStruct
|
|
|
521
558
|
|
|
522
559
|
private
|
|
523
560
|
|
|
524
|
-
# Deeply duplicate +@attributes+
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
@attributes.each { |k, v| attributes[k] = v.dup }
|
|
529
|
-
@attributes = attributes
|
|
561
|
+
# Deeply duplicate +@attributes+ and +@optional_attributes+
|
|
562
|
+
def initialize_copy(*)
|
|
563
|
+
@attributes = @attributes.transform_values(&:dup)
|
|
564
|
+
@optional_attributes = @optional_attributes.dup
|
|
530
565
|
end
|
|
531
566
|
|
|
532
567
|
# Force str to binary encoding
|
|
533
|
-
# @param [String]
|
|
568
|
+
# @param str [String]
|
|
534
569
|
# @return [String]
|
|
535
570
|
# @deprecated Prefer use of Ruby's {::String#b}
|
|
536
571
|
def force_binary(str)
|
|
537
572
|
BinStruct.force_binary(str)
|
|
538
573
|
end
|
|
539
574
|
|
|
540
|
-
# @param [Symbol]
|
|
575
|
+
# @param attr [Symbol] attribute name
|
|
541
576
|
# @return [Boolean] +true= if #from_human and #to_human are both defined for given attribute
|
|
542
577
|
def to_and_from_human?(attr)
|
|
543
578
|
self[attr].respond_to?(:to_human) && self[attr].respond_to?(:from_human)
|
|
544
579
|
end
|
|
545
580
|
|
|
581
|
+
# Return attribute definitions
|
|
582
|
+
# @return [Hash{Symbol=>StructDef}]
|
|
546
583
|
def attr_defs
|
|
547
584
|
self.class.attr_defs
|
|
548
585
|
end
|
|
549
586
|
|
|
550
587
|
# rubocop:disable Metrics/AbcSize
|
|
588
|
+
|
|
589
|
+
# Build attribute named +attr+
|
|
590
|
+
# @param attr [Symbol]
|
|
591
|
+
# @return [void]
|
|
551
592
|
def build_attribute(attr)
|
|
552
593
|
type = attr_defs[attr].type
|
|
553
594
|
|
|
@@ -561,6 +602,10 @@ module BinStruct
|
|
|
561
602
|
end
|
|
562
603
|
# rubocop:enable Metrics/AbcSize
|
|
563
604
|
|
|
605
|
+
# Initialize attribute with given value
|
|
606
|
+
# @param attr [Symbol]
|
|
607
|
+
# @param val [Object] value to set
|
|
608
|
+
# @return [void]
|
|
564
609
|
def initialize_value(attr, val)
|
|
565
610
|
type = attr_defs[attr].type
|
|
566
611
|
default = attr_defs[attr].default
|
|
@@ -576,7 +621,7 @@ module BinStruct
|
|
|
576
621
|
end
|
|
577
622
|
end
|
|
578
623
|
|
|
579
|
-
# @param [Symbol]
|
|
624
|
+
# @param attr [Symbol]
|
|
580
625
|
# @return [void]
|
|
581
626
|
def initialize_optional(attr)
|
|
582
627
|
optional = attr_defs[attr].optional
|
|
@@ -589,9 +634,9 @@ module BinStruct
|
|
|
589
634
|
"-- #{title} #{'-' * (66 - title.length)}\n"
|
|
590
635
|
end
|
|
591
636
|
|
|
592
|
-
# @param [
|
|
593
|
-
# @param [Structable]
|
|
594
|
-
# @param [Integer]
|
|
637
|
+
# @param attr [Symbol]
|
|
638
|
+
# @param value [Structable]
|
|
639
|
+
# @param level [Integer]
|
|
595
640
|
# @return [::String]
|
|
596
641
|
def inspect_attribute(attr, value, level = 1)
|
|
597
642
|
str = inspect_shift_level(level)
|
|
@@ -607,7 +652,7 @@ module BinStruct
|
|
|
607
652
|
str
|
|
608
653
|
end
|
|
609
654
|
|
|
610
|
-
# @param [Integer]
|
|
655
|
+
# @param level [Integer]
|
|
611
656
|
# @return [String]
|
|
612
657
|
def inspect_shift_level(level = 1)
|
|
613
658
|
' ' * (level + 1)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# This file is part of BinStruct
|
|
4
|
-
# see https://
|
|
4
|
+
# see https://codeberg.org/lemontree55/bin_struct for more informations
|
|
5
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
|
6
6
|
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
|
7
7
|
# This program is published under MIT license.
|
|
@@ -26,7 +26,7 @@ module BinStruct
|
|
|
26
26
|
# These methods are defined for documentation.
|
|
27
27
|
|
|
28
28
|
# Populate object from a binary string
|
|
29
|
-
# @param [::String]
|
|
29
|
+
# @param str [::String]
|
|
30
30
|
# @return [self]
|
|
31
31
|
# @abstract subclass should overload it.
|
|
32
32
|
def read(str)
|
data/lib/bin_struct/version.rb
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# This file is part of BinStruct
|
|
4
|
-
# see https://
|
|
4
|
+
# see https://codeberg.org/lemontree55/bin_struct for more informations
|
|
5
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
|
6
6
|
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
|
7
7
|
# This program is published under MIT license.
|
|
8
8
|
|
|
9
9
|
module BinStruct
|
|
10
10
|
# BinStruct version
|
|
11
|
-
VERSION = '0.5.
|
|
11
|
+
VERSION = '0.5.3'
|
|
12
12
|
end
|
data/lib/bin_struct.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# This file is part of BinStruct
|
|
4
|
-
# see https://
|
|
4
|
+
# see https://codeberg.org/lemontree55/bin_struct for more informations
|
|
5
5
|
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
|
|
6
6
|
# Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
|
|
7
7
|
# This program is published under MIT license.
|
|
@@ -39,7 +39,7 @@ module BinStruct
|
|
|
39
39
|
class Error < StandardError; end
|
|
40
40
|
|
|
41
41
|
# Force binary encoding for +str+
|
|
42
|
-
# @param [String]
|
|
42
|
+
# @param str [String]
|
|
43
43
|
# @return [String] binary encoded string
|
|
44
44
|
# @deprecated Use {::String#b} instead of this method
|
|
45
45
|
def self.force_binary(str)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bin_struct
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- LemonTree55
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-01-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: 'BinStruct is a binary dissector and generator. It eases manipulating
|
|
14
14
|
complex binary data.
|
|
@@ -37,13 +37,14 @@ files:
|
|
|
37
37
|
- lib/bin_struct/struct.rb
|
|
38
38
|
- lib/bin_struct/structable.rb
|
|
39
39
|
- lib/bin_struct/version.rb
|
|
40
|
-
homepage: https://
|
|
40
|
+
homepage: https://codeberg.org/lemontree55/bin_struct
|
|
41
41
|
licenses:
|
|
42
42
|
- MIT
|
|
43
43
|
metadata:
|
|
44
|
-
homepage_uri: https://
|
|
45
|
-
source_code_uri: https://
|
|
46
|
-
bug_tracker_uri: https://
|
|
44
|
+
homepage_uri: https://codeberg.org/lemontree55/bin_struct
|
|
45
|
+
source_code_uri: https://codeberg.org/lemontree55/bin_struct
|
|
46
|
+
bug_tracker_uri: https://codeberg.org/lemontree55/bin_struct/issues
|
|
47
|
+
rubygems_mfa_required: 'true'
|
|
47
48
|
post_install_message:
|
|
48
49
|
rdoc_options:
|
|
49
50
|
- "--title"
|
|
@@ -58,14 +59,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
58
59
|
requirements:
|
|
59
60
|
- - ">="
|
|
60
61
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: 3.
|
|
62
|
+
version: 3.1.0
|
|
62
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
64
|
requirements:
|
|
64
65
|
- - ">="
|
|
65
66
|
- !ruby/object:Gem::Version
|
|
66
67
|
version: '0'
|
|
67
68
|
requirements: []
|
|
68
|
-
rubygems_version: 3.3.
|
|
69
|
+
rubygems_version: 3.3.27
|
|
69
70
|
signing_key:
|
|
70
71
|
specification_version: 4
|
|
71
72
|
summary: Binary dissector and generator
|