Sha256: a456e13ecb8b98d319cc93d9870590b3ab6ba0c939c5573aae4efdbb3a301e76

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

module Python
  module Pickle
    #
    # Common base class for all protocol implementations.
    #
    class Protocol

      # The Pickle stream to read or write to.
      #
      # @return [IO]
      attr_reader :io

      #
      # Initializes the protocol.
      #
      # @param [IO] io
      #   The Pickle stream to read or write to.
      #
      def initialize(io)
        @io = io
      end

      #
      # Reads all instructions from the Pickle stream.
      #
      # @yield [instruction]
      #   If a block is given, it will be passed each parsed Pickle instruction.
      #
      # @yieldparam [Instruction] instruction
      #   A parsed Pickle instruction from the Pickle stream.
      #
      # @return [Array<Instruction>]
      #   All parsed Pickle instructions from the Pickle stream.
      #
      def read
        return enum_for(__method__).to_a unless block_given?

        until @io.eof?
          yield read_instruction
        end
      end

      #
      # Reads an instruction from the pickle stream.
      #
      # @return [Instruction]
      #
      # @abstract
      #
      def read_instruction
        raise(NotImplementedError,"#{self.class}##{__method__} was not implemented")
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
python-pickle-0.2.0 lib/python/pickle/protocol.rb
python-pickle-0.1.1 lib/python/pickle/protocol.rb
python-pickle-0.1.0 lib/python/pickle/protocol.rb