org.jruby.util
Class Pack

java.lang.Object
  extended by org.jruby.util.Pack

public class Pack
extends java.lang.Object


Nested Class Summary
static class Pack.Converter
           
 
Constructor Summary
Pack()
           
 
Method Summary
static void decode(Ruby runtime, java.nio.ByteBuffer encode, int occurrences, RubyArray result, Pack.Converter converter)
           
static int encode(Ruby runtime, int occurrences, java.lang.StringBuffer result, RubyArray list, int index, Pack.Converter converter)
           
static RubyString pack(Ruby runtime, RubyArray list, org.jruby.util.ByteList formatString)
          pack_pack Template characters for Array#pack Directive Meaning
Directive Meaning @ Moves to absolute position A ASCII string (space padded, count is width) a ASCII string (null padded, count is width) B Bit string (descending bit order) b Bit string (ascending bit order) C Unsigned char c Char d Double-precision float, native format E Double-precision float, little-endian byte order e Single-precision float, little-endian byte order f Single-precision float, native format G Double-precision float, network (big-endian) byte order g Single-precision float, network (big-endian) byte order H Hex string (high nibble first) h Hex string (low nibble first) I Unsigned integer i Integer L Unsigned long l Long M Quoted printable, MIME encoding (see RFC2045) m Base64 encoded string N Long, network (big-endian) byte order n Short, network (big-endian) byte-order P Pointer to a structure (fixed-length string) p Pointer to a null-terminated string Q Unsigned 64-bit number q 64-bit number S Unsigned short s Short U UTF-8 u UU-encoded string V Long, little-endian byte order v Short, little-endian byte order X Back up a byte x Null byte Z Same as ``A'' Packs the contents of arr into a binary sequence according to the directives in aTemplateString (see preceding table).
static RubyArray unpack(Ruby runtime, org.jruby.util.ByteList encodedString, org.jruby.util.ByteList formatString)
          Decodes str (which may contain binary data) according to the format string, returning an array of each value extracted.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Pack

public Pack()
Method Detail

unpack

public static RubyArray unpack(Ruby runtime,
                               org.jruby.util.ByteList encodedString,
                               org.jruby.util.ByteList formatString)
Decodes str (which may contain binary data) according to the format string, returning an array of each value extracted. The format string consists of a sequence of single-character directives.
Each directive may be followed by a number, indicating the number of times to repeat with this directive. An asterisk (``*'') will use up all remaining elements.
The directives sSiIlL may each be followed by an underscore (``_'') to use the underlying platform's native size for the specified type; otherwise, it uses a platform-independent consistent size.
Spaces are ignored in the format string.

See Also:

Directives for String#unpack
Format Function Returns
A String with trailing nulls and spaces removed. String
a String. String
B Extract bits from each character (msb first). String
b Extract bits from each character (lsb first). String
C Extract a character as an unsigned integer. Fixnum
c Extract a character as an integer. Fixnum
d Treat sizeof(double) characters as a native double. Float
E Treat sizeof(double) characters as a double in little-endian byte order. Float
e Treat sizeof(float) characters as a float in little-endian byte order. Float
f Treat sizeof(float) characters as a native float. Float
G Treat sizeof(double) characters as a double in network byte order. Float
g Treat sizeof(float) characters as a float in network byte order. Float
H Extract hex nibbles from each character (most significant first). String
h Extract hex nibbles from each character (least significant first). String
I Treat sizeof(int) 1 successive characters as an unsigned native integer. Integer
i Treat sizeof(int) 1 successive characters as a signed native integer. Integer
L Treat four1 successive characters as an unsigned native long integer. Integer
l Treat four1 successive characters as a signed native long integer. Integer
M Extract a quoted-printable string. String
m Extract a base64 encoded string. String
N Treat four characters as an unsigned long in network byte order. Fixnum
n Treat two characters as an unsigned short in network byte order. Fixnum
P Treat sizeof(char *) characters as a pointer, and return len characters from the referenced location. String
p Treat sizeof(char *) characters as a pointer to a null-terminated string. String
S Treat two1 successive characters as an unsigned short in native byte order. Fixnum
s Treat two1 successive characters as a signed short in native byte order. Fixnum
U Extract UTF-8 characters as unsigned integers. Integer
u Extract a UU-encoded string. String
V Treat four characters as an unsigned long in little-endian byte order. Fixnum
v Treat two characters as an unsigned short in little-endian byte order. Fixnum
X Skip backward one character. ---
x Skip forward one character. ---
Z String with trailing nulls removed. String
@ Skip to the offset given by the length argument. ---

1 May be modified by appending ``_'' to the directive.


decode

public static void decode(Ruby runtime,
                          java.nio.ByteBuffer encode,
                          int occurrences,
                          RubyArray result,
                          Pack.Converter converter)

encode

public static int encode(Ruby runtime,
                         int occurrences,
                         java.lang.StringBuffer result,
                         RubyArray list,
                         int index,
                         Pack.Converter converter)

pack

public static RubyString pack(Ruby runtime,
                              RubyArray list,
                              org.jruby.util.ByteList formatString)
pack_pack Template characters for Array#pack Directive Meaning
Directive Meaning
@ Moves to absolute position
A ASCII string (space padded, count is width)
a ASCII string (null padded, count is width)
B Bit string (descending bit order)
b Bit string (ascending bit order)
C Unsigned char
c Char
d Double-precision float, native format
E Double-precision float, little-endian byte order
e Single-precision float, little-endian byte order
f Single-precision float, native format
G Double-precision float, network (big-endian) byte order
g Single-precision float, network (big-endian) byte order
H Hex string (high nibble first)
h Hex string (low nibble first)
I Unsigned integer
i Integer
L Unsigned long
l Long
M Quoted printable, MIME encoding (see RFC2045)
m Base64 encoded string
N Long, network (big-endian) byte order
n Short, network (big-endian) byte-order
P Pointer to a structure (fixed-length string)
p Pointer to a null-terminated string
Q Unsigned 64-bit number
q 64-bit number
S Unsigned short
s Short
U UTF-8
u UU-encoded string
V Long, little-endian byte order
v Short, little-endian byte order
X Back up a byte
x Null byte
Z Same as ``A''
Packs the contents of arr into a binary sequence according to the directives in aTemplateString (see preceding table). Directives ``A,'' ``a,'' and ``Z'' may be followed by a count, which gives the width of the resulting field. The remaining directives also may take a count, indicating the number of array elements to convert. If the count is an asterisk (``*''] = all remaining array elements will be converted. Any of the directives ``sSiIlL'' may be followed by an underscore (``_'') to use the underlying platform's native size for the specified type; otherwise, they use a platform-independent size. Spaces are ignored in the template string.

See Also:
RubyString.unpack(org.jruby.runtime.builtin.IRubyObject)


Copyright © 2002-2007 JRuby Team. All Rights Reserved.