module Avro::SchemaCompatibility
Public Class Methods
can_read?(writers_schema, readers_schema)
click to toggle source
# File lib/avro/schema_compatibility.rb 18 def self.can_read?(writers_schema, readers_schema) 19 Checker.new.can_read?(writers_schema, readers_schema) 20 end
match_schemas(writers_schema, readers_schema)
click to toggle source
# File lib/avro/schema_compatibility.rb 26 def self.match_schemas(writers_schema, readers_schema) 27 # Note: this does not support aliases! 28 w_type = writers_schema.type_sym 29 r_type = readers_schema.type_sym 30 31 # This conditional is begging for some OO love. 32 if w_type == :union || r_type == :union 33 return true 34 end 35 36 if w_type == r_type 37 return true if Schema::PRIMITIVE_TYPES_SYM.include?(r_type) 38 39 case r_type 40 when :record 41 return writers_schema.fullname == readers_schema.fullname 42 when :error 43 return writers_schema.fullname == readers_schema.fullname 44 when :request 45 return true 46 when :fixed 47 return writers_schema.fullname == readers_schema.fullname && 48 writers_schema.size == readers_schema.size 49 when :enum 50 return writers_schema.fullname == readers_schema.fullname 51 when :map 52 return match_schemas(writers_schema.values, readers_schema.values) 53 when :array 54 return match_schemas(writers_schema.items, readers_schema.items) 55 end 56 end 57 58 # Handle schema promotion 59 if w_type == :int && [:long, :float, :double].include?(r_type) 60 return true 61 elsif w_type == :long && [:float, :double].include?(r_type) 62 return true 63 elsif w_type == :float && r_type == :double 64 return true 65 elsif w_type == :string && r_type == :bytes 66 return true 67 elsif w_type == :bytes && r_type == :string 68 return true 69 end 70 71 return false 72 end
mutual_read?(writers_schema, readers_schema)
click to toggle source
# File lib/avro/schema_compatibility.rb 22 def self.mutual_read?(writers_schema, readers_schema) 23 Checker.new.mutual_read?(writers_schema, readers_schema) 24 end