Module: Lumberjack::FrameEncoder

Defined in:
lib/lumberjack/client.rb

Overview

JsonEncoder

Class Method Summary collapse

Class Method Details

.to_frame(hash, sequence) ⇒ Object


179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/lumberjack/client.rb', line 179

def self.to_frame(hash, sequence)
  frame = ["1", "D", sequence]
  pack = "AAN"
  keys = deep_keys(hash)
  frame << keys.length
  pack << "N"
  keys.each do |k|
    val = deep_get(hash,k)
    key_length = k.bytesize
    val_length = val.bytesize
    frame << key_length
    pack << "N"
    frame << k
    pack << "A#{key_length}"
    frame << val_length
    pack << "N"
    frame << val
    pack << "A#{val_length}"
  end
  frame.pack(pack)
end