module Avromatic::Model::RawSerialization::Encode
Constants
- UNSPECIFIED
Public Instance Methods
Source
# File lib/avromatic/model/raw_serialization.rb, line 77 def avro_key_datum(validate: UNSPECIFIED) unless validate == UNSPECIFIED ActiveSupport::Deprecation.warn("The 'validate' argument to #{__method__} is deprecated.") end avro_hash(key_avro_field_references, strict: true) end
Source
# File lib/avromatic/model/raw_serialization.rb, line 35 def avro_raw_key(validate: UNSPECIFIED) unless validate == UNSPECIFIED ActiveSupport::Deprecation.warn("The 'validate' argument to #{__method__} is deprecated.") end raise 'Model has no key schema' unless key_avro_schema avro_raw_encode(key_attributes_for_avro, :key) end
Source
# File lib/avromatic/model/raw_serialization.rb, line 23 def avro_raw_value(validate: UNSPECIFIED) unless validate == UNSPECIFIED ActiveSupport::Deprecation.warn("The 'validate' argument to #{__method__} is deprecated.") end if self.class.recursively_immutable? @avro_raw_value ||= avro_raw_encode(value_attributes_for_avro, :value) else avro_raw_encode(value_attributes_for_avro, :value) end end
rubocop:enable Style/AccessModifierDeclarations
Source
# File lib/avromatic/model/raw_serialization.rb, line 65 def avro_value_datum(validate: UNSPECIFIED) unless validate == UNSPECIFIED ActiveSupport::Deprecation.warn("The 'validate' argument to #{__method__} is deprecated.") end if self.class.recursively_immutable? @avro_value_datum ||= avro_hash(value_avro_field_references, strict: true) else avro_hash(value_avro_field_references, strict: true) end end
Source
# File lib/avromatic/model/raw_serialization.rb, line 57 def key_attributes_for_avro(validate: UNSPECIFIED) unless validate == UNSPECIFIED ActiveSupport::Deprecation.warn("The 'validate' argument to #{__method__} is deprecated.") end avro_hash(key_avro_field_references) end
Source
# File lib/avromatic/model/raw_serialization.rb, line 45 def value_attributes_for_avro(validate: UNSPECIFIED) unless validate == UNSPECIFIED ActiveSupport::Deprecation.warn("The 'validate' argument to #{__method__} is deprecated.") end if self.class.recursively_immutable? @value_attributes_for_avro ||= avro_hash(value_avro_field_references) else avro_hash(value_avro_field_references) end end
Private Instance Methods
Source
# File lib/avromatic/model/raw_serialization.rb, line 87 def avro_hash(field_references, strict: false) field_references.each_with_object(Hash.new) do |field_reference, result| attribute_definition = self.class.attribute_definitions[field_reference.name_sym] value = _attributes[field_reference.name_sym] if value.nil? && !attribute_definition.nullable? # We're missing a required attribute so perform an explicit validation to generate # a more complete error message avro_validate! elsif _attributes.include?(field_reference.name_sym) begin result[field_reference.name] = attribute_definition.serialize(value, strict) rescue Avromatic::Model::ValidationError # Perform an explicit validation to generate a more complete error message avro_validate! # We should never get here but just in case... raise end end end end
Source
# File lib/avromatic/model/raw_serialization.rb, line 109 def avro_raw_encode(data, key_or_value = :value) stream = StringIO.new encoder = Avro::IO::BinaryEncoder.new(stream) datum_writer[key_or_value].write(data, encoder) stream.string end