Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse json messages into intermediate format
Significantly improves performance as now each json message is parsed exactly/only once. Specs updated + added to test new algorithm
- Loading branch information
Showing
14 changed files
with
284 additions
and
157 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# RJR Request Message | ||
# | ||
# Copyright (C) 2012-2014 Mohammed Morsi <mo@morsi.org> | ||
# Licensed under the Apache License, Version 2.0 | ||
|
||
require 'json' | ||
require 'rjr/util/json_parser' | ||
|
||
module RJR | ||
module Messages | ||
|
||
# Intermediate representation of a JSON-RPC data containing | ||
# extracted/parsed data which has not been analysed. | ||
class Intermediate | ||
# JSON from which data is extracted from | ||
attr_accessor :json | ||
|
||
# Data extracted from message | ||
attr_accessor :data | ||
|
||
def initialize(args = {}) | ||
@json = args[:json] || nil | ||
@data = args[:data] || {} | ||
end | ||
|
||
def keys | ||
data.keys | ||
end | ||
|
||
def [](key) | ||
data[key.to_s] | ||
end | ||
|
||
def has?(key) | ||
data.key?(key) | ||
end | ||
|
||
def self.parse(json) | ||
parsed = nil | ||
|
||
#allow parsing errs to propagate up | ||
parsed = JSONParser.parse(json) | ||
|
||
self.new :json => json, | ||
:data => parsed | ||
end | ||
|
||
end # class Intermediate | ||
end # module Messages | ||
end # module RJR |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.