Module: RubySol
- Defined in:
- lib/ruby_sol/class_mapping.rb,
lib/ruby_sol.rb,
lib/ruby_sol/constants.rb,
lib/ruby_sol/class_mapping.rb,
lib/ruby_sol/pure/io_helpers.rb,
lib/ruby_sol/pure/serializer.rb,
lib/ruby_sol/pure/deserializer.rb
Overview
require ‘ruby_sol/values/typed_hash’ require ‘ruby_sol/values/messages’
Defined Under Namespace
Modules: Pure, Values Classes: AMFError, ClassMapping, MappingSet, SOLError
Constant Summary collapse
- Deserializer =
RubySol::Pure::Deserializer
- Serializer =
RubySol::Pure::Serializer
- AMF0_NUMBER_MARKER =
AMF0 Type Markers
0x00
- AMF0_BOOLEAN_MARKER =
“000”
0x01
- AMF0_STRING_MARKER =
“001”
0x02
- AMF0_OBJECT_MARKER =
“002”
0x03
- AMF0_MOVIE_CLIP_MARKER =
“003”
0x04
- AMF0_NULL_MARKER =
“004” # Unused
0x05
- AMF0_UNDEFINED_MARKER =
“005”
0x06
- AMF0_REFERENCE_MARKER =
“006”
0x07
- AMF0_HASH_MARKER =
“a”
0x08
- AMF0_OBJECT_END_MARKER =
“b”
0x09
- AMF0_STRICT_ARRAY_MARKER =
“t”
0x0A
- AMF0_DATE_MARKER =
“n”
0x0B
- AMF0_LONG_STRING_MARKER =
“v”
0x0C
- AMF0_UNSUPPORTED_MARKER =
“f”
0x0D
- AMF0_RECORDSET_MARKER =
“r”
0x0E
- AMF0_XML_MARKER =
“016” # Unused
0x0F
- AMF0_TYPED_OBJECT_MARKER =
“017”
0x10
- AMF0_AMF3_MARKER =
“020”
0x11
- AMF3_UNDEFINED_MARKER =
AMF3 Type Markers
0x00
- AMF3_NULL_MARKER =
“000”
0x01
- AMF3_FALSE_MARKER =
“001”
0x02
- AMF3_TRUE_MARKER =
“002”
0x03
- AMF3_INTEGER_MARKER =
“003”
0x04
- AMF3_DOUBLE_MARKER =
“004”
0x05
- AMF3_STRING_MARKER =
“005”
0x06
- AMF3_XML_DOC_MARKER =
“006”
0x07
- AMF3_DATE_MARKER =
“a”
0x08
- AMF3_ARRAY_MARKER =
“b”
0x09
- AMF3_OBJECT_MARKER =
“t”
0x0A
- AMF3_XML_MARKER =
“n”
0x0B
- AMF3_BYTE_ARRAY_MARKER =
“v”
0x0C
- AMF3_VECTOR_INT_MARKER =
“f”
0x0D
- AMF3_VECTOR_UINT_MARKER =
“r”
0x0E
- AMF3_VECTOR_DOUBLE_MARKER =
“016”
0x0F
- AMF3_VECTOR_OBJECT_MARKER =
“017”
0x10
- AMF3_DICT_MARKER =
“020”
0x11
- AMF3_EMPTY_STRING =
Other AMF3 Markers
0x01
- AMF3_CLOSE_DYNAMIC_OBJECT =
0x01
- AMF3_CLOSE_DYNAMIC_ARRAY =
0x01
- MAX_INTEGER =
Other Constants
268435455
- MIN_INTEGER =
-268435456
Class Method Summary collapse
-
.const_missing(const) ⇒ Object
We use const_missing to define the active ClassMapper at runtime.
- .create_sol(content) ⇒ Object
-
.deserialize(source, amf_version = 0) ⇒ Object
to have RocketAMF specs compatibility.
-
.read_sol(source) ⇒ Object
usage RubySol::read_sol(File.new(filename, ‘r:ASCII-8BIT’).read).
- .serialize(obj, amf_version = 0) ⇒ Object
Class Method Details
.const_missing(const) ⇒ Object
We use const_missing to define the active ClassMapper at runtime. This way, heavy modification of class mapping functionality is still possible without forcing extenders to redefine the constant.
90 91 92 93 94 95 96 |
# File 'lib/ruby_sol.rb', line 90 def self.const_missing const #:nodoc: if const == :ClassMapper RubySol.const_set(:ClassMapper, RubySol::ClassMapping) else super(const) end end |
.create_sol(content) ⇒ Object
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 |
# File 'lib/ruby_sol.rb', line 60 def self.create_sol(content) name = content['__ruby_sol__sol_name'] || 'unknown' version = content['__ruby_sol__amf_version'] || 0 ser = RubySol::Serializer.new(RubySol::ClassMapper.new) ser.stream << SOL_SIGNATURE ser.amf0_write_string_wo_marker(name) ser.stream << SOL_PADDING * 3 ser.stream << [version].pack('c') content.each_key { |key| if key !~ /^__ruby_sol__/ if version == 0 ser.amf0_write_string_wo_marker(key) ser.amf0_serialize(content[key]) ser.stream << SOL_PADDING elsif version == 3 ser.amf3_write_utf8_vr(key) ser.amf3_serialize(content[key]) ser.stream << SOL_PADDING end end } res = ser.stream return SOL_HEADER.force_encoding("ASCII-8BIT") + [res.bytesize].pack('N').force_encoding("ASCII-8BIT") + res.force_encoding("ASCII-8BIT") end |
.deserialize(source, amf_version = 0) ⇒ Object
to have RocketAMF specs compatibility
99 100 101 102 |
# File 'lib/ruby_sol.rb', line 99 def self.deserialize source, amf_version = 0 des = RubySol::Deserializer.new(RubySol::ClassMapper.new) des.deserialize(amf_version, source) end |
.read_sol(source) ⇒ Object
usage RubySol::read_sol(File.new(filename, ‘r:ASCII-8BIT’).read)
22 23 24 25 26 27 28 29 30 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 |
# File 'lib/ruby_sol.rb', line 22 def self.read_sol(source) if StringIO === source f = source elsif source f = StringIO.new(source) elsif f.nil? raise AMFError, "no source to deserialize" end header = f.read(2) len=f.read(4).unpack('N').first throw SOLError, 'bad size' unless (len + 6 == f.size) signature = f.read(10) throw SOLError, 'bad signature' unless (signature == SOL_SIGNATURE) des = RubySol::Deserializer.new(RubySol::ClassMapper.new) des.source = f sol_name=des.amf0_read_string() zeros=f.read(3) throw SOLError, 'bad signature' unless (zeros == SOL_PADDING * 3) amf_version = f.read(1).unpack('C').first values = {'__ruby_sol__amf_version' => amf_version, '__ruby_sol__sol_name' => sol_name } des.source = f while !f.eof? str = amf_version == 3? des.amf3_read_string() : des.amf0_read_string(); obj = amf_version == 3? des.amf3_deserialize() : des.amf0_deserialize(); values[str] = obj padding = f.read(1); end return values end |
.serialize(obj, amf_version = 0) ⇒ Object
103 104 105 106 |
# File 'lib/ruby_sol.rb', line 103 def self.serialize obj, amf_version = 0 ser = RubySol::Serializer.new(RubySol::ClassMapper.new) ser.serialize(amf_version, obj) end |