class Avro::IO::BinaryDecoder
FIXME(jmhodges) move validate to this module?
Attributes
reader[R]
reader is an object on which we can call read, seek and tell.
Public Class Methods
new(reader)
click to toggle source
# File lib/avro/io.rb 42 def initialize(reader) 43 @reader = reader 44 end
Public Instance Methods
byte!()
click to toggle source
# File lib/avro/io.rb 46 def byte! 47 @reader.readbyte 48 end
read(len)
click to toggle source
# File lib/avro/io.rb 105 def read(len) 106 # Read n bytes 107 @reader.read(len) 108 end
read_boolean()
click to toggle source
# File lib/avro/io.rb 55 def read_boolean 56 byte! == 1 57 end
read_bytes()
click to toggle source
# File lib/avro/io.rb 91 def read_bytes 92 # Bytes are encoded as a long followed by that many bytes of 93 # data. 94 read(read_long) 95 end
read_double()
click to toggle source
# File lib/avro/io.rb 83 def read_double 84 # A double is written as 8 bytes. 85 # The double is converted into a 64-bit integer using a method 86 # equivalent to Java's doubleToLongBits and then encoded in 87 # little-endian format. 88 read_and_unpack(8, 'E') 89 end
read_float()
click to toggle source
# File lib/avro/io.rb 75 def read_float 76 # A float is written as 4 bytes. 77 # The float is converted into a 32-bit integer using a method 78 # equivalent to Java's floatToIntBits and then encoded in 79 # little-endian format. 80 read_and_unpack(4, 'e') 81 end
read_int()
click to toggle source
# File lib/avro/io.rb 59 def read_int; read_long; end
read_long()
click to toggle source
# File lib/avro/io.rb 61 def read_long 62 # int and long values are written using variable-length, 63 # zig-zag coding. 64 b = byte! 65 n = b & 0x7F 66 shift = 7 67 while (b & 0x80) != 0 68 b = byte! 69 n |= (b & 0x7F) << shift 70 shift += 7 71 end 72 (n >> 1) ^ -(n & 1) 73 end
read_null()
click to toggle source
# File lib/avro/io.rb 50 def read_null 51 # null is written as zero byte's 52 nil 53 end
read_string()
click to toggle source
# File lib/avro/io.rb 97 def read_string 98 # A string is encoded as a long followed by that many bytes of 99 # UTF-8 encoded character data. 100 read_bytes.tap do |string| 101 string.force_encoding('UTF-8') if string.respond_to? :force_encoding 102 end 103 end
skip(n)
click to toggle source
# File lib/avro/io.rb 145 def skip(n) 146 reader.seek(reader.tell() + n) 147 end
skip_boolean()
click to toggle source
# File lib/avro/io.rb 114 def skip_boolean 115 skip(1) 116 end
skip_bytes()
click to toggle source
# File lib/avro/io.rb 137 def skip_bytes 138 skip(read_long) 139 end
skip_double()
click to toggle source
# File lib/avro/io.rb 133 def skip_double 134 skip(8) 135 end
skip_float()
click to toggle source
# File lib/avro/io.rb 129 def skip_float 130 skip(4) 131 end
skip_int()
click to toggle source
# File lib/avro/io.rb 118 def skip_int 119 skip_long 120 end
skip_long()
click to toggle source
# File lib/avro/io.rb 122 def skip_long 123 b = byte! 124 while (b & 0x80) != 0 125 b = byte! 126 end 127 end
skip_null()
click to toggle source
# File lib/avro/io.rb 110 def skip_null 111 nil 112 end
skip_string()
click to toggle source
# File lib/avro/io.rb 141 def skip_string 142 skip_bytes 143 end
Private Instance Methods
read_and_unpack(byte_count, format)
click to toggle source
# File lib/avro/io.rb 154 def read_and_unpack(byte_count, format) 155 @reader.read(byte_count).unpack1(format) 156 end