module FFWD::Plugin::Protobuf::Serializer
Constants
- LATEST_VERSION
- VERSIONS
Public Class Methods
dump_event(event)
click to toggle source
# File lib/ffwd/plugin/protobuf/serializer.rb, line 48 def self.dump_event event unless impl = VERSIONS[LATEST_VERSION] raise "No implementation for latest version: #{LATEST_VERSION}" end dump_frame impl.dump_event event end
dump_frame(string)
click to toggle source
# File lib/ffwd/plugin/protobuf/serializer.rb, line 25 def self.dump_frame string [LATEST_VERSION, string.length + 8].pack("NN") + string end
dump_metric(metric)
click to toggle source
# File lib/ffwd/plugin/protobuf/serializer.rb, line 56 def self.dump_metric metric unless impl = VERSIONS[LATEST_VERSION] raise "No implementation for latest version: #{LATEST_VERSION}" end dump_frame impl.dump_metric metric end
load(string) { |type, data| ... }
click to toggle source
# File lib/ffwd/plugin/protobuf/serializer.rb, line 64 def self.load string impl, string = load_frame string impl.load string do |type, data| yield type, data end end
load_frame(string)
click to toggle source
# File lib/ffwd/plugin/protobuf/serializer.rb, line 29 def self.load_frame string if string.length < 8 raise "Frame too small, expected at least 8 bytes but got #{string.length}" end version = string[0..3].unpack("N")[0] length = string[4..7].unpack("N")[0] unless impl = VERSIONS[version] raise "Unsupported protocol version #{version}, latest is #{LATEST_VERSION}" end if length != string.length raise "Message length invalid, expected #{length} but got #{string.length}" end [impl, string[8..length]] end