U:RDoc::AnyMethod[iI" pack:ETI"Array#pack;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"JPacks the contents of arr into a binary sequence according to ;TI"Dthe directives in aTemplateString (see the table below) ;TI"DDirectives ``A,'' ``a,'' and ``Z'' may be followed by a count, ;TI"Awhich gives the width of the resulting field. The remaining ;TI"Fdirectives also may take a count, indicating the number of array ;TI"6elements to convert. If the count is an asterisk ;TI"@(``*
''), all remaining array elements will be ;TI"Econverted. Any of the directives ``sSiIlL
'' may be ;TI"7followed by an underscore (``_
'') or ;TI"Aexclamation mark (``!
'') to use the underlying ;TI"Jplatform's native size for the specified type; otherwise, they use a ;TI"Cplatform-independent size. Spaces are ignored in the template ;TI"1string. See also String#unpack
.;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim; [
I"a = [ "a", "b", "c" ]
;TI"n = [ 65, 66, 67 ]
;TI"(a.pack("A3A3A3") #=> "a b c "
;TI":a.pack("a3a3a3") #=> "a\000\000b\000\000c\000\000"
;TI""n.pack("ccc") #=> "ABC"
;T:@format0o;
; [I"FIf aBufferString is specified and its capacity is enough, ;TI"2+pack+ uses it as the buffer and returns it. ;TI"NWhen the offset is specified by the beginning of aTemplateString, ;TI",the result is filled after the offset. ;TI"NIf original contents of aBufferString exists and it's longer than ;TI"Rthe offset, the rest of offsetOfBuffer are overwritten by the result. ;TI"AIf it's shorter, the gap is filled with ``\0
''.;T@o;
; [I"LNote that ``buffer:'' option does not guarantee not to allocate memory ;TI"Hin +pack+. If the capacity of aBufferString is not enough, ;TI"+pack+ allocates memory.;T@o;
; [I"Directives for +pack+.;T@o;; []I"Integer | Array |
;TI"'Directive | Element | Meaning
;TI"R----------------------------------------------------------------------------
;TI">C | Integer | 8-bit unsigned (unsigned char)
;TI"IS | Integer | 16-bit unsigned, native endian (uint16_t)
;TI"IL | Integer | 32-bit unsigned, native endian (uint32_t)
;TI"IQ | Integer | 64-bit unsigned, native endian (uint64_t)
;TI"QJ | Integer | pointer width unsigned, native endian (uintptr_t)
;TI"@ | | (J is available since Ruby 2.3.)
;TI" | |
;TI":c | Integer | 8-bit signed (signed char)
;TI"Fs | Integer | 16-bit signed, native endian (int16_t)
;TI"Fl | Integer | 32-bit signed, native endian (int32_t)
;TI"Fq | Integer | 64-bit signed, native endian (int64_t)
;TI"Nj | Integer | pointer width signed, native endian (intptr_t)
;TI"@ | | (j is available since Ruby 2.3.)
;TI" | |
;TI"=S_ S! | Integer | unsigned short, native endian
;TI";I I_ I! | Integer | unsigned int, native endian
;TI" s> S!> s!> | Integer | same as the directives without ">" except
;TI"*L> l> L!> l!> | | big endian
;TI" i!> | | (available since Ruby 1.9.3)
;TI"3Q> q> Q!> q!> | | "S>" is same as "n"
;TI"3J> j> J!> j!> | | "L>" is same as "N"
;TI" | |
;TI"IS< s< S!< s!< | Integer | same as the directives without "<" except
;TI"-L< l< L!< l!< | | little endian
;TI"D d | Float | double-precision, native format
;TI">F f | Float | single-precision, native format
;TI"IE | Float | double-precision, little-endian byte order
;TI"Ie | Float | single-precision, little-endian byte order
;TI"PG | Float | double-precision, network (big-endian) byte order
;TI"Pg | Float | single-precision, network (big-endian) byte order
;TI"
;TI"String | Array |
;TI"&Directive | Element | Meaning
;TI"Q---------------------------------------------------------------------------
;TI"UA | String | arbitrary binary string (space padded, count is width)
;TI"Ta | String | arbitrary binary string (null padded, count is width)
;TI"NZ | String | same as ``a'', except that null is added with *
;TI"5B | String | bit string (MSB first)
;TI"5b | String | bit string (LSB first)
;TI"=H | String | hex string (high nibble first)
;TI" aBinaryString
arr.pack( aTemplateString, buffer: aBufferString ) -> aBufferString
;T0[ I"(p1, p2 = {});T@ˆFI"
Array;TcRDoc::NormalClass00