Sha256: d50563dec79ab311448b9f9854bb15ae545731369a214f30281c300b133c66f3

Contents?: true

Size: 755 Bytes

Versions: 11

Compression:

Stored size: 755 Bytes

Contents

# frozen_string_literal: true

module Paquito
  class SingleBytePrefixVersion
    def initialize(current_version, coders)
      @current_version = current_version
      @coders = coders.transform_values { |c| Paquito.cast(c) }
      @current_coder = coders.fetch(current_version)
    end

    def dump(object)
      @current_version.chr(Encoding::BINARY) << @current_coder.dump(object)
    end

    def load(payload)
      payload_version = payload.getbyte(0)
      unless payload_version
        raise UnsupportedCodec, "Missing version byte."
      end

      coder = @coders.fetch(payload_version) do
        raise UnsupportedCodec, "Unsupported packer version #{payload_version}"
      end
      coder.load(payload.byteslice(1..-1))
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
paquito-0.7.0 lib/paquito/single_byte_prefix_version.rb
paquito-0.6.2 lib/paquito/single_byte_prefix_version.rb
paquito-0.6.1 lib/paquito/single_byte_prefix_version.rb
paquito-0.6.0 lib/paquito/single_byte_prefix_version.rb
paquito-0.5.0 lib/paquito/single_byte_prefix_version.rb
paquito-0.4.0 lib/paquito/single_byte_prefix_version.rb
paquito-0.3.1 lib/paquito/single_byte_prefix_version.rb
paquito-0.3.0 lib/paquito/single_byte_prefix_version.rb
paquito-0.2.1 lib/paquito/single_byte_prefix_version.rb
paquito-0.2.0 lib/paquito/single_byte_prefix_version.rb
paquito-0.1.0 lib/paquito/single_byte_prefix_version.rb