Class: Python::Pickle::Protocol1 Private
- Defined in:
- lib/python/pickle/protocol1.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Implements reading and writing of Python Pickle protocol 1.
Direct Known Subclasses
Constant Summary collapse
- OPCODES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Opcodes for Pickle protocol version 1.
Protocol0::OPCODES + Set[ 41, # EMPTY_TUPLE 71, # BINFLOAT 75, # BININT1 84, # BINSTRING 85, # SHORT_BINSTRING 88, # BINUNICODE 93, # EMPTY_LIST 101, # APPENDS 113, # BINPUT 117, # SETITEMS 125 # EMPTY_DICT ]
Instance Attribute Summary
Attributes inherited from Protocol
Instance Method Summary collapse
-
#read_float64_be ⇒ Float
private
Reads a double precision (64bit) floating point number, in network byte-order (big-endian).
-
#read_instruction ⇒ Instruction
private
Reads an instruction from the pickle stream.
-
#read_uint32_le ⇒ Integer
private
Reads an unsigned 32bit integer, in little-endian byte-order.
-
#read_uint8 ⇒ Integer
private
Reads a single 8bit unsigned integer (byte).
Methods inherited from Protocol0
#read_escaped_char, #read_float, #read_hex_escaped_char, #read_int, #read_long, #read_nl_string, #read_string, #read_unicode_escaped_char, #read_unicode_escaped_char16, #read_unicode_escaped_char32, #read_unicode_string
Methods inherited from Protocol
Constructor Details
This class inherits a constructor from Python::Pickle::Protocol
Instance Method Details
#read_float64_be ⇒ Float
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reads a double precision (64bit) floating point number, in network byte-order (big-endian).
159 160 161 |
# File 'lib/python/pickle/protocol1.rb', line 159 def read_float64_be @io.read(8).unpack1('G') end |
#read_instruction ⇒ Instruction
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reads an instruction from the pickle stream.
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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/python/pickle/protocol1.rb', line 62 def read_instruction case (opcode = @io.getbyte) # # Protocol 0 instructions # when 40 # MARK Instructions::MARK when 46 # STOP Instructions::STOP when 48 # POP Instructions::POP when 49 # POP_MARK Instructions::POP_MARK when 50 # DUP Instructions::DUP when 70 # FLOAT Instructions::Float.new(read_float) when 73 # INT Instructions::Int.new(read_int) when 76 # LONG Instructions::Long.new(read_long) when 78 # NONE Instructions::NONE when 82 # REDUCE Instructions::REDUCE when 83 # STRING Instructions::String.new(read_string) when 86 # UNICODE Instructions::String.new(read_unicode_string) when 97 # APPEND Instructions::APPEND when 98 # BUILD Instructions::BUILD when 99 # GLOBAL Instructions::Global.new(read_nl_string,read_nl_string) when 100 # DICT Instructions::DICT when 103 # GET Instructions::Get.new(read_int) when 108 # LIST Instructions::LIST when 112 # PUT Instructions::Put.new(read_int) when 115 # SETITEM Instructions::SETITEM when 116 # TUPLE Instructions::TUPLE # # Protocol 1 instructions # when 41 # EMPTY_TUPLE Instructions::EMPTY_TUPLE when 71 # BINFLOAT Instructions::BinFloat.new(read_float64_be) when 75 # BININT1 Instructions::BinInt1.new(read_uint8) when 84 # BINSTRING length = read_uint32_le string = @io.read(length) Instructions::BinString.new(length,string) when 85 # SHORT_BINSTRING length = read_uint8 string = @io.read(length) Instructions::ShortBinString.new(length,string) when 88 # BINUNICODE length = read_uint32_le string = @io.read(length).force_encoding(Encoding::UTF_8) Instructions::BinUnicode.new(length,string) when 93 # EMPTY_LIST Instructions::EMPTY_LIST when 101 # APPENDS Instructions::APPENDS when 104 # BINGET Instructions::BinGet.new(read_uint8) when 106 # LONG_BINGET Instructions::LongBinGet.new(read_uint32_le) when 113 # BINPUT Instructions::BinPut.new(read_uint8) when 117 # SETITEMS Instructions::SETITEMS when 125 # EMPTY_DICT Instructions::EMPTY_DICT else raise(InvalidFormat,"invalid opcode (#{opcode.inspect}) for protocol 1") end end |
#read_uint32_le ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reads an unsigned 32bit integer, in little-endian byte-order.
177 178 179 |
# File 'lib/python/pickle/protocol1.rb', line 177 def read_uint32_le @io.read(4).unpack1('L<') end |
#read_uint8 ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reads a single 8bit unsigned integer (byte).
168 169 170 |
# File 'lib/python/pickle/protocol1.rb', line 168 def read_uint8 @io.getbyte end |