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
41 def initialize(reader)
42   @reader = reader
43 end

Public Instance Methods

byte!() click to toggle source
   # File lib/avro/io.rb
45 def byte!
46   @reader.read(1).unpack('C').first
47 end
read(len) click to toggle source
    # File lib/avro/io.rb
104 def read(len)
105   # Read n bytes
106   @reader.read(len)
107 end
read_boolean() click to toggle source
   # File lib/avro/io.rb
54 def read_boolean
55   byte! == 1
56 end
read_bytes() click to toggle source
   # File lib/avro/io.rb
90 def read_bytes
91   # Bytes are encoded as a long followed by that many bytes of
92   # data.
93   read(read_long)
94 end
read_double() click to toggle source
   # File lib/avro/io.rb
82 def read_double
83   #  A double is written as 8 bytes.
84   # The double is converted into a 64-bit integer using a method
85   # equivalent to Java's doubleToLongBits and then encoded in
86   # little-endian format.
87   @reader.read(8).unpack('E')[0]
88 end
read_float() click to toggle source
   # File lib/avro/io.rb
74 def read_float
75   # A float is written as 4 bytes.
76   # The float is converted into a 32-bit integer using a method
77   # equivalent to Java's floatToIntBits and then encoded in
78   # little-endian format.
79   @reader.read(4).unpack('e')[0]
80 end
read_int() click to toggle source
   # File lib/avro/io.rb
58 def read_int; read_long; end
read_long() click to toggle source
   # File lib/avro/io.rb
60 def read_long
61   # int and long values are written using variable-length,
62   # zig-zag coding.
63   b = byte!
64   n = b & 0x7F
65   shift = 7
66   while (b & 0x80) != 0
67     b = byte!
68     n |= (b & 0x7F) << shift
69     shift += 7
70   end
71   (n >> 1) ^ -(n & 1)
72 end
read_null() click to toggle source
   # File lib/avro/io.rb
49 def read_null
50   # null is written as zero byte's
51   nil
52 end
read_string() click to toggle source
    # File lib/avro/io.rb
 96 def read_string
 97   # A string is encoded as a long followed by that many bytes of
 98   # UTF-8 encoded character data.
 99   read_bytes.tap do |string|
100     string.force_encoding("UTF-8") if string.respond_to? :force_encoding
101   end
102 end
skip(n) click to toggle source
    # File lib/avro/io.rb
144 def skip(n)
145   reader.seek(reader.tell() + n)
146 end
skip_boolean() click to toggle source
    # File lib/avro/io.rb
113 def skip_boolean
114   skip(1)
115 end
skip_bytes() click to toggle source
    # File lib/avro/io.rb
136 def skip_bytes
137   skip(read_long)
138 end
skip_double() click to toggle source
    # File lib/avro/io.rb
132 def skip_double
133   skip(8)
134 end
skip_float() click to toggle source
    # File lib/avro/io.rb
128 def skip_float
129   skip(4)
130 end
skip_int() click to toggle source
    # File lib/avro/io.rb
117 def skip_int
118   skip_long
119 end
skip_long() click to toggle source
    # File lib/avro/io.rb
121 def skip_long
122   b = byte!
123   while (b & 0x80) != 0
124     b = byte!
125   end
126 end
skip_null() click to toggle source
    # File lib/avro/io.rb
109 def skip_null
110   nil
111 end
skip_string() click to toggle source
    # File lib/avro/io.rb
140 def skip_string
141   skip_bytes
142 end