BinReadable
This mixin solely depends on method read(n), which must be defined in the class/module where you mix in this module.
Methods
- byte_order
- byte_order=
- byteorder
- byteorder=
- read_cstring
- read_int16_big
- read_int16_little
- read_int16_native
- read_int32_big
- read_int32_little
- read_int32_native
- read_int8
- read_uint8
- read_word16_big
- read_word16_little
- read_word16_native
- read_word32_big
- read_word32_little
- read_word32_native
- read_word8
- readn
Classes and Modules
Module BinReadable::ByteOrderPublic Instance methods
default is native byte-order
This method is also aliased as
byteorder
[ show source ]
# File lib/more/facets/binreadable.rb, line 74 def byte_order @byte_order || ByteOrder::Native end
This method is also aliased as
byteorder=
[ show source ]
# File lib/more/facets/binreadable.rb, line 78 def byte_order=(new_byteorder) @byte_order = new_byteorder end
Alias for byte_order
Alias for byte_order=
[ show source ]
# File lib/more/facets/binreadable.rb, line 188 def read_cstring str = "" while (c=readn(1)) != "\0" str << c end str end
[ show source ]
# File lib/more/facets/binreadable.rb, line 124 def read_int16_big # swap bytes if native=little (but we want big) ru_swap(2, 's', ByteOrder::Little) end
[ show source ]
# File lib/more/facets/binreadable.rb, line 119 def read_int16_little # swap bytes if native=big (but we want little) ru_swap(2, 's', ByteOrder::Big) end
Signed
[ show source ]
# File lib/more/facets/binreadable.rb, line 115 def read_int16_native ru(2, 's') end
[ show source ]
# File lib/more/facets/binreadable.rb, line 156 def read_int32_big # swap bytes if native=little (but we want big) ru_swap(4, 'l', ByteOrder::Little) end
[ show source ]
# File lib/more/facets/binreadable.rb, line 151 def read_int32_little # swap bytes if native=big (but we want little) ru_swap(4, 'l', ByteOrder::Big) end
Signed
[ show source ]
# File lib/more/facets/binreadable.rb, line 147 def read_int32_native ru(4, 'l') end
[ show source ]
# File lib/more/facets/binreadable.rb, line 93 def read_int8 ru(1, 'c') end
Alias for read_word8
[ show source ]
# File lib/more/facets/binreadable.rb, line 109 def read_word16_big ru(2, 'n') end
[ show source ]
# File lib/more/facets/binreadable.rb, line 105 def read_word16_little ru(2, 'v') end
Unsigned
[ show source ]
# File lib/more/facets/binreadable.rb, line 101 def read_word16_native ru(2, 'S') end
[ show source ]
# File lib/more/facets/binreadable.rb, line 141 def read_word32_big ru(4, 'N') end
[ show source ]
# File lib/more/facets/binreadable.rb, line 137 def read_word32_little ru(4, 'V') end
Unsigned
[ show source ]
# File lib/more/facets/binreadable.rb, line 133 def read_word32_native ru(4, 'L') end
no byteorder for 8 bit!
This method is also aliased as
read_uint8
[ show source ]
# File lib/more/facets/binreadable.rb, line 89 def read_word8 ru(1, 'C') end
read exactly n characters, otherwise raise an exception.
[ show source ]
# File lib/more/facets/binreadable.rb, line 197 def readn(n) str = read(n) raise "couldn't read #{n} characters" if str.nil? or str.size != n str end