lib/avro/io.rb in avro-1.7.3 vs lib/avro/io.rb in avro-1.7.4
- old
+ new
@@ -94,12 +94,13 @@
end
def read_string
# A string is encoded as a long followed by that many bytes of
# UTF-8 encoded character data.
- # FIXME utf-8 encode this in 1.9
- read_bytes
+ read_bytes.tap do |string|
+ string.force_encoding("UTF-8") if string.respond_to? :force_encoding
+ end
end
def read(len)
# Read n bytes
@reader.read(len)
@@ -242,11 +243,11 @@
case r_type
when 'record'
return check_props(writers_schema, readers_schema, [:fullname])
when 'error'
- return check_props(writers_scheam, readers_schema, [:fullname])
+ return check_props(writers_schema, readers_schema, [:fullname])
when 'request'
return true
when 'fixed'
return check_props(writers_schema, readers_schema, [:fullname, :size])
when 'enum'
@@ -312,11 +313,11 @@
when 'fixed'; read_fixed(writers_schema, readers_schema, decoder)
when 'enum'; read_enum(writers_schema, readers_schema, decoder)
when 'array'; read_array(writers_schema, readers_schema, decoder)
when 'map'; read_map(writers_schema, readers_schema, decoder)
when 'union'; read_union(writers_schema, readers_schema, decoder)
- when 'record', 'errors', 'request'; read_record(writers_schema, readers_schema, decoder)
+ when 'record', 'error', 'request'; read_record(writers_schema, readers_schema, decoder)
else
raise AvroError, "Cannot read unknown schema type: #{writers_schema.type}"
end
end
@@ -440,22 +441,22 @@
read_map[key] = map_val
end
return read_map
when 'union'
return read_default_value(field_schema.schemas[0], default_value)
- when 'record'
+ when 'record', 'error'
read_record = {}
field_schema.fields.each do |field|
json_val = default_value[field.name]
json_val = field.default unless json_val
field_val = read_default_value(field.type, json_val)
read_record[field.name] = field_val
end
return read_record
else
fail_msg = "Unknown type: #{field_schema.type}"
- raise AvroError(fail_msg)
+ raise AvroError, fail_msg
end
end
def skip_data(writers_schema, decoder)
case writers_schema.type
@@ -563,10 +564,10 @@
when 'fixed'; write_fixed(writers_schema, datum, encoder)
when 'enum'; write_enum(writers_schema, datum, encoder)
when 'array'; write_array(writers_schema, datum, encoder)
when 'map'; write_map(writers_schema, datum, encoder)
when 'union'; write_union(writers_schema, datum, encoder)
- when 'record', 'errors', 'request'; write_record(writers_schema, datum, encoder)
+ when 'record', 'error', 'request'; write_record(writers_schema, datum, encoder)
else
raise AvroError.new("Unknown type: #{writers_schema.type}")
end
end