2019-11-08 05:54:39 +03:00
|
|
|
class Array
|
|
|
|
# call-seq:
|
2022-10-18 18:16:22 +03:00
|
|
|
# pack(template, buffer: nil) -> string
|
2019-11-08 05:54:39 +03:00
|
|
|
#
|
2022-10-18 18:16:22 +03:00
|
|
|
# Formats each element in +self+ into a binary string; returns that string.
|
|
|
|
# See {Packed Data}[rdoc-ref:packed_data.rdoc].
|
2019-11-08 05:54:39 +03:00
|
|
|
def pack(fmt, buffer: nil)
|
2020-05-31 09:52:32 +03:00
|
|
|
Primitive.pack_pack(fmt, buffer)
|
2019-11-08 05:54:39 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class String
|
|
|
|
# call-seq:
|
2024-09-29 13:09:59 +03:00
|
|
|
# unpack(template, offset: 0, &block) -> array
|
|
|
|
#
|
|
|
|
# Extracts data from +self+.
|
|
|
|
#
|
|
|
|
# If +block+ is not given, forming objects that become the elements
|
|
|
|
# of a new array, and returns that array. Otherwise, yields each
|
|
|
|
# object.
|
2019-11-08 05:54:39 +03:00
|
|
|
#
|
2022-10-18 18:16:22 +03:00
|
|
|
# See {Packed Data}[rdoc-ref:packed_data.rdoc].
|
2021-10-18 17:23:54 +03:00
|
|
|
def unpack(fmt, offset: 0)
|
2024-03-27 01:29:38 +03:00
|
|
|
Primitive.attr! :use_block
|
2021-10-18 17:23:54 +03:00
|
|
|
Primitive.pack_unpack(fmt, offset)
|
2019-11-08 05:54:39 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
# call-seq:
|
2022-10-18 18:16:22 +03:00
|
|
|
# unpack1(template, offset: 0) -> object
|
2021-12-23 23:58:13 +03:00
|
|
|
#
|
2022-10-18 18:16:22 +03:00
|
|
|
# Like String#unpack, but unpacks and returns only the first extracted object.
|
|
|
|
# See {Packed Data}[rdoc-ref:packed_data.rdoc].
|
2021-10-18 17:23:54 +03:00
|
|
|
def unpack1(fmt, offset: 0)
|
|
|
|
Primitive.pack_unpack1(fmt, offset)
|
2019-11-08 05:54:39 +03:00
|
|
|
end
|
|
|
|
end
|