Class: RSpecTracer::Storage::Serializer::Msgpack Private
- Inherits:
-
Object
- Object
- RSpecTracer::Storage::Serializer::Msgpack
- Defined in:
- lib/rspec_tracer/storage/serializer/msgpack.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.
MessagePack + zlib serializer. msgpack encode is ~2x smaller than pretty JSON on our representative dependency graphs; zlib deflate then buys another ~5x on path-repetitive payloads (dependency.json is the big one - the same path string appears once per example that touched it). Combined ratio matches the ~4-6x claim in remote_cache/archive.rb.
Stdlib zlib avoids adding a second gem dep; msgpack itself is
the single new dev-group gem. Users who want the backend
add gem 'msgpack' to their own Gemfile per
USER_FACING_SURFACE.md optional-dep convention.
The require is lazy so pure-Ruby suites that stay on :json do not pay the msgpack load cost and so the LoadError path is exercisable in unit specs (hide_const-based).
Type extensions: Ruby Time and Symbol values surface in
example metadata (RSpec's execution_result.started_at is a
Time; status values like :passed / :failed / :flaky are
Symbols on the in-memory snapshot). The bare msgpack default
registry has no Time packer (crashes
NoMethodError: undefined method 'to_msgpack') and silently
coerces Symbol to String (lossy round-trip). Both
behaviors broke the cache on the first run a user followed
the 50 MiB warning's :msgpack recommendation. Registering
Factory type extensions for Time (ID 0x00, 12-byte
seconds+nanoseconds payload) and Symbol (ID 0x01, UTF-8
string payload) gives lossless round-trip. The factory is
memoized so the extension registration is one-shot per
process.
Constant Summary collapse
- TIME_EXTENSION_TYPE =
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.
Internal constant —
MessagePack::Factory#register_typeID for RubyTime. Codepoint chosen from the user-space range (0x00–0x7F per msgpack ext spec); collision-safe with the built-in timestamp ext (ID -1 / 0xFF) since IDs are disjoint. 0x00- SYMBOL_EXTENSION_TYPE =
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.
Internal constant —
MessagePack::Factory#register_typeID for RubySymbol. See TIME_EXTENSION_TYPE rationale. 0x01
Class Method Summary collapse
-
.available? ⇒ Boolean
private
Probe used by JsonBackend#initialize to decide whether to fall back to the Json serializer at construct time.
-
.decode(bytes) ⇒ Object
private
Internal helper for the tracer pipeline.
-
.encode(payload) ⇒ Object
private
Internal helper for the tracer pipeline.
-
.extension ⇒ Object
private
Internal helper for the tracer pipeline.
Class Method Details
.available? ⇒ Boolean
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.
Probe used by JsonBackend#initialize to decide whether to
fall back to the Json serializer at construct time. True
iff require 'msgpack' succeeds; false when the gem is
missing. Idempotent without an explicit memo because Ruby's
require short-circuits via $LOADED_FEATURES on repeat
calls and defined?(::MessagePack) cheaply detects the
post-load constant. The previous @msgpack_loaded ivar memo
was load-bearing for mutation observability: once any prior
test tripped the memo, mutations on the require line were
observably equivalent.
90 91 92 93 94 95 |
# File 'lib/rspec_tracer/storage/serializer/msgpack.rb', line 90 def self.available? ensure_available! true rescue MsgpackGemNotInstalled false end |
.decode(bytes) ⇒ Object
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.
Internal helper for the tracer pipeline.
76 77 78 |
# File 'lib/rspec_tracer/storage/serializer/msgpack.rb', line 76 def self.decode(bytes) factory.unpack(::Zlib::Inflate.inflate(bytes)) end |
.encode(payload) ⇒ Object
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.
Internal helper for the tracer pipeline.
70 71 72 |
# File 'lib/rspec_tracer/storage/serializer/msgpack.rb', line 70 def self.encode(payload) ::Zlib::Deflate.deflate(factory.pack(payload)) end |
.extension ⇒ Object
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.
Internal helper for the tracer pipeline.
64 65 66 |
# File 'lib/rspec_tracer/storage/serializer/msgpack.rb', line 64 def self.extension 'msgpack.gz' end |