Class: Zrip::FrameCodec
- Inherits:
-
Object
- Object
- Zrip::FrameCodec
- Defined in:
- lib/zrip/frame_codec.rb
Overview
Zstandard frame-format codec.
FrameCodec is Ractor-shareable. It uses an internal lock around native
compression and decompression contexts.
Class Method Summary collapse
-
._native_new(dict, id, level) ⇒ FrameCodec
Native constructor used by
.new. -
.get_frame_content_size(bytes) ⇒ Integer?
Read
Frame_Content_Sizefrom a Zstandard frame header. -
.new(dict: nil, level: DEFAULT_LEVEL) ⇒ FrameCodec
Create a frame codec.
Instance Method Summary collapse
-
#_native_decompress(bytes, max_output_size) ⇒ String
Native decompression entry used by #decompress.
-
#compress(bytes) ⇒ String
Compress bytes to a Zstandard frame.
-
#decompress(bytes, max_output_size: nil) ⇒ String
Decompress a Zstandard frame.
- #has_dict? ⇒ Boolean
-
#id ⇒ Integer?
Dictionary ID.
-
#level ⇒ Integer
Compression level.
-
#size ⇒ Integer
Dictionary size in bytes.
Class Method Details
._native_new(dict, id, level) ⇒ FrameCodec
Native constructor used by .new.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/zrip/frame_codec.rb', line 64 class FrameCodec def self.new(dict: nil, level: DEFAULT_LEVEL) case dict when nil _native_new(nil, 0, Integer(level)) when Dictionary _native_new(dict.bytes, dict.id, Integer(level)) when String d = Dictionary.new(bytes: dict) _native_new(d.bytes, d.id, Integer(level)) else raise TypeError, "expected Zrip::Dictionary, String, or nil; got #{dict.class}" end end def decompress(bytes, max_output_size: nil) _native_decompress(bytes, Integer(max_output_size || 0)) end end |
.get_frame_content_size(bytes) ⇒ Integer?
Read Frame_Content_Size from a Zstandard frame header.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/zrip/frame_codec.rb', line 64 class FrameCodec def self.new(dict: nil, level: DEFAULT_LEVEL) case dict when nil _native_new(nil, 0, Integer(level)) when Dictionary _native_new(dict.bytes, dict.id, Integer(level)) when String d = Dictionary.new(bytes: dict) _native_new(d.bytes, d.id, Integer(level)) else raise TypeError, "expected Zrip::Dictionary, String, or nil; got #{dict.class}" end end def decompress(bytes, max_output_size: nil) _native_decompress(bytes, Integer(max_output_size || 0)) end end |
.new(dict: nil, level: DEFAULT_LEVEL) ⇒ FrameCodec
Create a frame codec.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/zrip/frame_codec.rb', line 64 class FrameCodec def self.new(dict: nil, level: DEFAULT_LEVEL) case dict when nil _native_new(nil, 0, Integer(level)) when Dictionary _native_new(dict.bytes, dict.id, Integer(level)) when String d = Dictionary.new(bytes: dict) _native_new(d.bytes, d.id, Integer(level)) else raise TypeError, "expected Zrip::Dictionary, String, or nil; got #{dict.class}" end end def decompress(bytes, max_output_size: nil) _native_decompress(bytes, Integer(max_output_size || 0)) end end |
Instance Method Details
#_native_decompress(bytes, max_output_size) ⇒ String
Native decompression entry used by #decompress.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/zrip/frame_codec.rb', line 64 class FrameCodec def self.new(dict: nil, level: DEFAULT_LEVEL) case dict when nil _native_new(nil, 0, Integer(level)) when Dictionary _native_new(dict.bytes, dict.id, Integer(level)) when String d = Dictionary.new(bytes: dict) _native_new(d.bytes, d.id, Integer(level)) else raise TypeError, "expected Zrip::Dictionary, String, or nil; got #{dict.class}" end end def decompress(bytes, max_output_size: nil) _native_decompress(bytes, Integer(max_output_size || 0)) end end |
#compress(bytes) ⇒ String
Compress bytes to a Zstandard frame.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/zrip/frame_codec.rb', line 64 class FrameCodec def self.new(dict: nil, level: DEFAULT_LEVEL) case dict when nil _native_new(nil, 0, Integer(level)) when Dictionary _native_new(dict.bytes, dict.id, Integer(level)) when String d = Dictionary.new(bytes: dict) _native_new(d.bytes, d.id, Integer(level)) else raise TypeError, "expected Zrip::Dictionary, String, or nil; got #{dict.class}" end end def decompress(bytes, max_output_size: nil) _native_decompress(bytes, Integer(max_output_size || 0)) end end |
#decompress(bytes, max_output_size: nil) ⇒ String
Decompress a Zstandard frame.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/zrip/frame_codec.rb', line 64 class FrameCodec def self.new(dict: nil, level: DEFAULT_LEVEL) case dict when nil _native_new(nil, 0, Integer(level)) when Dictionary _native_new(dict.bytes, dict.id, Integer(level)) when String d = Dictionary.new(bytes: dict) _native_new(d.bytes, d.id, Integer(level)) else raise TypeError, "expected Zrip::Dictionary, String, or nil; got #{dict.class}" end end def decompress(bytes, max_output_size: nil) _native_decompress(bytes, Integer(max_output_size || 0)) end end |
#has_dict? ⇒ Boolean
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/zrip/frame_codec.rb', line 64 class FrameCodec def self.new(dict: nil, level: DEFAULT_LEVEL) case dict when nil _native_new(nil, 0, Integer(level)) when Dictionary _native_new(dict.bytes, dict.id, Integer(level)) when String d = Dictionary.new(bytes: dict) _native_new(d.bytes, d.id, Integer(level)) else raise TypeError, "expected Zrip::Dictionary, String, or nil; got #{dict.class}" end end def decompress(bytes, max_output_size: nil) _native_decompress(bytes, Integer(max_output_size || 0)) end end |
#id ⇒ Integer?
Returns dictionary ID.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/zrip/frame_codec.rb', line 64 class FrameCodec def self.new(dict: nil, level: DEFAULT_LEVEL) case dict when nil _native_new(nil, 0, Integer(level)) when Dictionary _native_new(dict.bytes, dict.id, Integer(level)) when String d = Dictionary.new(bytes: dict) _native_new(d.bytes, d.id, Integer(level)) else raise TypeError, "expected Zrip::Dictionary, String, or nil; got #{dict.class}" end end def decompress(bytes, max_output_size: nil) _native_decompress(bytes, Integer(max_output_size || 0)) end end |
#level ⇒ Integer
Returns compression level.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/zrip/frame_codec.rb', line 64 class FrameCodec def self.new(dict: nil, level: DEFAULT_LEVEL) case dict when nil _native_new(nil, 0, Integer(level)) when Dictionary _native_new(dict.bytes, dict.id, Integer(level)) when String d = Dictionary.new(bytes: dict) _native_new(d.bytes, d.id, Integer(level)) else raise TypeError, "expected Zrip::Dictionary, String, or nil; got #{dict.class}" end end def decompress(bytes, max_output_size: nil) _native_decompress(bytes, Integer(max_output_size || 0)) end end |
#size ⇒ Integer
Returns dictionary size in bytes.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/zrip/frame_codec.rb', line 64 class FrameCodec def self.new(dict: nil, level: DEFAULT_LEVEL) case dict when nil _native_new(nil, 0, Integer(level)) when Dictionary _native_new(dict.bytes, dict.id, Integer(level)) when String d = Dictionary.new(bytes: dict) _native_new(d.bytes, d.id, Integer(level)) else raise TypeError, "expected Zrip::Dictionary, String, or nil; got #{dict.class}" end end def decompress(bytes, max_output_size: nil) _native_decompress(bytes, Integer(max_output_size || 0)) end end |