Class: RSpecTracer::Storage::Serializer::Msgpack Private

Inherits:
Object
  • Object
show all
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).

Class Method Summary collapse

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.

Returns:

  • (Boolean)


65
66
67
68
69
70
# File 'lib/rspec_tracer/storage/serializer/msgpack.rb', line 65

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.



50
51
52
53
# File 'lib/rspec_tracer/storage/serializer/msgpack.rb', line 50

def self.decode(bytes)
  ensure_available!
  ::MessagePack.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.



43
44
45
46
# File 'lib/rspec_tracer/storage/serializer/msgpack.rb', line 43

def self.encode(payload)
  ensure_available!
  ::Zlib::Deflate.deflate(::MessagePack.pack(payload))
end

.extensionObject

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.



37
38
39
# File 'lib/rspec_tracer/storage/serializer/msgpack.rb', line 37

def self.extension
  'msgpack.gz'
end