def serialized_marc(options)
      unless (options.keys - SERIALZED_MARC_VALID_OPTIONS).empty?
        raise RuntimeError.new("Illegal/Unknown argument '#{(options.keys - SERIALZED_MARC_VALID_OPTIONS).join(', ')}' in seralized_marc at #{Traject::Util.extract_caller_location(caller.first)}")
      end

      format          = options[:format].to_s
      binary_escape   = (options[:binary_escape] != false)
      allow_oversized = (options[:allow_oversized] == true)

      raise ArgumentError.new("Need :format => [binary|xml|json] arg") unless %w{binary xml json}.include?(format)

      lambda do |record, accumulator, context|
        case format
        when "binary"
          binary = MARC::Writer.encode(record, allow_oversized)
          binary = Base64.encode64(binary) if binary_escape
          accumulator << binary
        when "xml"
          accumulator << MARC::FastXMLWriter.encode(record)
        when "json"
          accumulator << JSON.dump(record.to_hash)
        end
      end
    end
def serialized_marc(options)
      unless (options.keys - SERIALZED_MARC_VALID_OPTIONS).empty?
        raise RuntimeError.new("Illegal/Unknown argument '#{(options.keys - SERIALZED_MARC_VALID_OPTIONS).join(', ')}' in seralized_marc at #{Traject::Util.extract_caller_location(caller.first)}")
      end

      format          = options[:format].to_s
      binary_escape   = (options[:binary_escape] != false)
      allow_oversized = (options[:allow_oversized] == true)

      raise ArgumentError.new("Need :format => [binary|xml|json] arg") unless %w{binary xml json}.include?(format)

      lambda do |record, accumulator, context|
        case format
        when "binary"
          binary = MARC::Writer.encode(record, allow_oversized)
          binary = Base64.encode64(binary) if binary_escape
          accumulator << binary
        when "xml"
          accumulator << MARC::FastXMLWriter.encode(record)
        when "json"
          accumulator << JSON.dump(record.to_hash)
        end
      end
    end
Serializes complete marc record to a serialization format.
 required param :format,
 serialize_marc(:format => :binary)

 formats:
 [xml] MarcXML
 [json] marc-in-json (http://dilettantes.code4lib.org/blog/2010/09/a-proposal-to-serialize-marc-in-json/)
 [binary] Standard ISO 2709 binary marc. By default WILL be base64-encoded,
          assumed destination a solr 'binary' field.
          * add option `:binary_escape => false` to do straight binary -- unclear
          what Solr's documented behavior is when you do this, and add a string
          with binary control chars to solr. May do different things in diff
          Solr versions, including raising exceptions.
          * add option `:allow_oversized => true` to pass that flat
          to the MARC::Writer. Oversized records will then still be
          serialized, with certain header bytes filled with ascii 0's
          -- technically illegal MARC, but can still be read by
          ruby MARC::Reader in permissive mode.