Skip to content

Instantly share code, notes, and snippets.

@killme2008
Created January 28, 2013 07:31
Show Gist options
  • Save killme2008/4653668 to your computer and use it in GitHub Desktop.
Save killme2008/4653668 to your computer and use it in GitHub Desktop.
A ruby script to parse metaq data
## Description: A ruby script to parse metaq data
## Requirements: sudo gem install bindata
require 'rubygems'
require 'bindata'
class Attribute < BinData::Record
endian :big
int32 :len,:initial_value => 0
string :attribute,:read_length => :len
end
class Message < BinData::Record
endian :big
int32 :len
int32 :checksum
int64 :msg_id
int32 :flag
attribute :attr,:onlyif => :has_attr?
string :payload,:read_length => lambda { attr.len > 0 ?(len - attr.len - 4): len}
def has_attr?
flag.nonzero?
end
end
File.open("00000000000000000000.meta","r") do |f|
count = 0
size = 0
max_size = 0
while !f.eof? and msg = Message.read(f)
count = count.succ
size = size + msg.payload.size
max_size = msg.payload.size if msg.payload.size > max_size
puts msg.payload if msg.payload.size >= 1024*1024
end
puts "Count:#{count},Size:#{size},Average:#{size.to_f/count},Max:#{max_size}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment