Class: Python::Pickle::Protocol

Inherits:
Object
  • Object
show all
Defined in:
lib/python/pickle/protocol.rb

Overview

Common base class for all protocol implementations.

Direct Known Subclasses

Protocol0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Protocol

Initializes the protocol.

Parameters:

  • io (IO)

    The Pickle stream to read or write to.



19
20
21
# File 'lib/python/pickle/protocol.rb', line 19

def initialize(io)
  @io = io
end

Instance Attribute Details

#ioIO (readonly)

The Pickle stream to read or write to.

Returns:

  • (IO)


11
12
13
# File 'lib/python/pickle/protocol.rb', line 11

def io
  @io
end

Instance Method Details

#read {|instruction| ... } ⇒ Array<Instruction>

Reads all instructions from the Pickle stream.

Yields:

  • (instruction)

    If a block is given, it will be passed each parsed Pickle instruction.

Yield Parameters:

  • instruction (Instruction)

    A parsed Pickle instruction from the Pickle stream.

Returns:

  • (Array<Instruction>)

    All parsed Pickle instructions from the Pickle stream.



35
36
37
38
39
40
41
# File 'lib/python/pickle/protocol.rb', line 35

def read
  return enum_for(__method__).to_a unless block_given?

  until @io.eof?
    yield read_instruction
  end
end

#read_instructionInstruction

This method is abstract.

Reads an instruction from the pickle stream.

Returns:

Raises:

  • (NotImplementedError)


50
51
52
# File 'lib/python/pickle/protocol.rb', line 50

def read_instruction
  raise(NotImplementedError,"#{self.class}##{__method__} was not implemented")
end