Created
August 12, 2009 00:06
-
-
Save brianmario/166198 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module EventMachine | |
module Protocols | |
module JsonProtocol | |
def post_init | |
@parser = Yajl::Parser.new | |
@parser.on_parse_complete = method(:receive_object) | |
@encoder = Yajl::Encoder.new | |
end | |
def receive_data(data) | |
@parser << data | |
end | |
# Invoked with ruby objects received over the network | |
def receive_object(obj) | |
# stub | |
end | |
# Sends a ruby object over the network | |
def send_object(obj) | |
# attempts to hand the caller 8kb chunks of the buffer as | |
# it's being generated | |
@encoder.encode(obj) do |chunk| | |
send_data(chunk) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment