Class: Python::Pickle::Protocol3

Inherits:
Protocol2 show all
Defined in:
lib/python/pickle/protocol3.rb

Direct Known Subclasses

Protocol4

Constant Summary collapse

BINBYTES =

The BINBYTES opcode.

66
SHORT_BINBYTES =

The SHORT_BINBYTES opcode.

67

Constants inherited from Protocol2

Python::Pickle::Protocol2::EXT1, Python::Pickle::Protocol2::EXT2, Python::Pickle::Protocol2::EXT4, Python::Pickle::Protocol2::LONG1, Python::Pickle::Protocol2::LONG4, Python::Pickle::Protocol2::NEWFALSE, Python::Pickle::Protocol2::NEWOBJ, Python::Pickle::Protocol2::NEWTRUE, Python::Pickle::Protocol2::PROTO, Python::Pickle::Protocol2::TUPLE1, Python::Pickle::Protocol2::TUPLE2, Python::Pickle::Protocol2::TUPLE3

Constants inherited from Protocol1

Python::Pickle::Protocol1::APPENDS, Python::Pickle::Protocol1::BINFLOAT, Python::Pickle::Protocol1::BINGET, Python::Pickle::Protocol1::BININT1, Python::Pickle::Protocol1::BINPUT, Python::Pickle::Protocol1::BINSTRING, Python::Pickle::Protocol1::BINUNICODE, Python::Pickle::Protocol1::EMPTY_DICT, Python::Pickle::Protocol1::EMPTY_LIST, Python::Pickle::Protocol1::EMPTY_TUPLE, Python::Pickle::Protocol1::LONG_BINGET, Python::Pickle::Protocol1::SETITEMS, Python::Pickle::Protocol1::SHORT_BINSTRING

Constants inherited from Protocol0

Python::Pickle::Protocol0::APPEND, Python::Pickle::Protocol0::BINPERSID, Python::Pickle::Protocol0::BUILD, Python::Pickle::Protocol0::DICT, Python::Pickle::Protocol0::DUP, Python::Pickle::Protocol0::FLOAT, Python::Pickle::Protocol0::GET, Python::Pickle::Protocol0::GLOBAL, Python::Pickle::Protocol0::INST, Python::Pickle::Protocol0::INT, Python::Pickle::Protocol0::LIST, Python::Pickle::Protocol0::LONG, Python::Pickle::Protocol0::MARK, Python::Pickle::Protocol0::NONE, Python::Pickle::Protocol0::OBJ, Python::Pickle::Protocol0::PERSID, Python::Pickle::Protocol0::POP, Python::Pickle::Protocol0::POP_MARK, Python::Pickle::Protocol0::PUT, Python::Pickle::Protocol0::REDUCE, Python::Pickle::Protocol0::SETITEM, Python::Pickle::Protocol0::STOP, Python::Pickle::Protocol0::STRING, Python::Pickle::Protocol0::TUPLE, Python::Pickle::Protocol0::UNICODE

Instance Attribute Summary

Attributes inherited from Protocol

#io

Instance Method Summary collapse

Methods inherited from Protocol2

#read_ext1_instruction, #read_ext2_instruction, #read_ext4_instruction, #read_int_le, #read_long1_instruction, #read_long4_instruction, #read_proto_instruction, #read_uint16_le, #unpack_int_le

Methods inherited from Protocol1

#read_binfloat_instruction, #read_binget_instruction, #read_binint1_instruction, #read_binput_instruction, #read_binstring_instruction, #read_binunicode_instruction, #read_float64_be, #read_long_binget_instruction, #read_short_binstring_instruction, #read_uint32_le, #read_uint8

Methods inherited from Protocol0

#read_escaped_char, #read_float, #read_float_instruction, #read_get_instruction, #read_global_instruction, #read_hex_escaped_char, #read_inst_instruction, #read_int, #read_int_instruction, #read_long, #read_long_instruction, #read_nl_string, #read_persid_instruction, #read_put_instruction, #read_string, #read_string_instruction, #read_unicode_escaped_char, #read_unicode_escaped_char16, #read_unicode_escaped_char32, #read_unicode_instruction, #read_unicode_string

Methods inherited from Protocol

#initialize, #read

Constructor Details

This class inherits a constructor from Python::Pickle::Protocol

Instance Method Details

#read_binbytes_instructionInstructions::BinBytes

Reads a BINBYTES instruction.

Returns:

Since:

  • 0.2.0



109
110
111
112
113
114
# File 'lib/python/pickle/protocol3.rb', line 109

def read_binbytes_instruction
  length = read_uint32_le
  bytes  = @io.read(length)

  Instructions::BinBytes.new(length,bytes)
end

#read_instructionInstruction

Reads an instruction from the pickle stream.

Returns:

Raises:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/python/pickle/protocol3.rb', line 31

def read_instruction
  case (opcode = @io.getbyte)
  #
  # Protocol 0 instructions
  #
  when MARK      then Instructions::MARK
  when STOP      then Instructions::STOP
  when POP       then Instructions::POP
  when POP_MARK  then Instructions::POP_MARK
  when DUP       then Instructions::DUP
  when FLOAT     then read_float_instruction
  when INT       then read_int_instruction
  when LONG      then read_long_instruction
  when NONE      then Instructions::NONE
  when REDUCE    then Instructions::REDUCE
  when STRING    then read_string_instruction
  when UNICODE   then read_unicode_instruction
  when APPEND    then Instructions::APPEND
  when BUILD     then Instructions::BUILD
  when GLOBAL    then read_global_instruction
  when DICT      then Instructions::DICT
  when GET       then read_get_instruction
  when LIST      then Instructions::LIST
  when PUT       then read_put_instruction
  when SETITEM   then Instructions::SETITEM
  when TUPLE     then Instructions::TUPLE
  when INST      then read_inst_instruction
  when OBJ       then Instructions::OBJ
  when PERSID    then read_persid_instruction
  when BINPERSID then Instructions::BINPERSID
  #
  # Protocol 1 instructions
  #
  when EMPTY_TUPLE     then Instructions::EMPTY_TUPLE
  when BINFLOAT        then read_binfloat_instruction
  when BININT1         then read_binint1_instruction
  when BINSTRING       then read_binstring_instruction
  when SHORT_BINSTRING then read_short_binstring_instruction
  when BINUNICODE      then read_binunicode_instruction
  when EMPTY_LIST      then Instructions::EMPTY_LIST
  when APPENDS         then Instructions::APPENDS
  when BINGET          then read_binget_instruction
  when LONG_BINGET     then read_long_binget_instruction
  when BINPUT          then read_binput_instruction
  when SETITEMS        then Instructions::SETITEMS
  when EMPTY_DICT      then Instructions::EMPTY_DICT
  #
  # Protocol 2 instructions
  #
  when PROTO    then read_proto_instruction
  when NEWOBJ   then Instructions::NEWOBJ
  when EXT1     then read_ext1_instruction
  when EXT2     then read_ext2_instruction
  when EXT4     then read_ext4_instruction
  when TUPLE1   then Instructions::TUPLE1
  when TUPLE2   then Instructions::TUPLE2
  when TUPLE3   then Instructions::TUPLE3
  when NEWTRUE  then Instructions::NEWTRUE
  when NEWFALSE then Instructions::NEWFALSE
  when LONG1    then read_long1_instruction
  when LONG4    then read_long4_instruction
  #
  # Protocol 3 instructions
  #
  when BINBYTES       then read_binbytes_instruction
  when SHORT_BINBYTES then read_short_binbytes_instruction
  else
    raise(InvalidFormat,"invalid opcode (#{opcode.inspect}) for protocol 3")
  end
end

#read_short_binbytes_instructionInstructions::ShortBinBytes

Reads a SHORT_BINBYTES instruction.

Returns:

Since:

  • 0.2.0



123
124
125
126
127
128
# File 'lib/python/pickle/protocol3.rb', line 123

def read_short_binbytes_instruction
  length = read_uint8
  bytes  = @io.read(length)

  Instructions::ShortBinBytes.new(length,bytes)
end