Class: Paquito::CommentPrefixVersion
- Inherits:
-
Object
- Object
- Paquito::CommentPrefixVersion
- Defined in:
- lib/paquito/comment_prefix_version.rb
Constant Summary collapse
- PREFIX =
"#\u2620"
- SUFFIX =
"\u2622\n"
- VERSION_POSITION =
PREFIX.bytesize
- HEADER_SLICE =
(0..(PREFIX.bytesize + SUFFIX.bytesize))
- PAYLOAD_SLICE =
(PREFIX.bytesize + 1 + SUFFIX.bytesize)..-1
- DEFAULT_VERSION =
0
Instance Method Summary collapse
- #dump(object) ⇒ Object
-
#initialize(current_version, coders) ⇒ CommentPrefixVersion
constructor
A new instance of CommentPrefixVersion.
- #load(payload) ⇒ Object
Constructor Details
#initialize(current_version, coders) ⇒ CommentPrefixVersion
Returns a new instance of CommentPrefixVersion.
13 14 15 16 17 18 19 20 21 |
# File 'lib/paquito/comment_prefix_version.rb', line 13 def initialize(current_version, coders) unless (0..9).cover?(current_version) && coders.keys.all? { |version| (0..9).cover?(version) } raise ArgumentError, "CommentPrefixVersion versions must be between 0 and 9" end @current_version = current_version @coders = coders.transform_values { |c| Paquito.cast(c) }.freeze @current_coder = coders.fetch(current_version) end |
Instance Method Details
#dump(object) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/paquito/comment_prefix_version.rb', line 23 def dump(object) prefix = +"#{PREFIX}#{@current_version}#{SUFFIX}" payload = @current_coder.dump(object) if payload.encoding == Encoding::BINARY prefix.b << payload else prefix << payload end end |
#load(payload) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/paquito/comment_prefix_version.rb', line 33 def load(payload) payload_version, serial = extract_version(payload) coder = @coders.fetch(payload_version) do raise UnsupportedCodec, "Unsupported packer version #{payload_version}" end coder.load(serial) end |