-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadFIXFieldSpec.rb
More file actions
74 lines (55 loc) · 1.89 KB
/
ReadFIXFieldSpec.rb
File metadata and controls
74 lines (55 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env ruby
#
require 'rexml/document'
require 'rexml/streamlistener'
require ENV["FLV_HOME"]+"/FixSpecFileLocator"
# class to read the names and number of all the fields
# from the QuickfixJ XML config file
class FieldListener
include REXML::StreamListener
attr(:allFields, true)
attr(:messageTypes, true)
def tag_start(name, attrs)
if(name == "field" && attrs["number"] != nil && attrs["name"] != nil)
#puts "got field: " + attrs["name"] + " with number " + attrs["number"]
@allFields[attrs["number"]] = attrs["name"]
if(@allFields["longestNameLength"] == nil)
@allFields["longestNameLength"] = attrs["name"].length
else
if(attrs["name"].length > @allFields["longestNameLength"])
@allFields["longestNameLength"] = attrs["name"].length
end
end
end
if(name == "message" && attrs["name"] != nil && attrs["msgtype"] != nil && attrs["msgcat"] != nil)
@messageTypes[attrs["msgtype"]] = attrs["name"]
end
end
end
class AllFixFields
def initialize(tag8)
@log = Logger.new(STDOUT)
@log.level = Logger::INFO
@allFields = {}
@messageTypes = {}
#quickFixJFile = AllQuickfixFIXFiles.new.localFixPaths[tag8]
quickFixJFile = FixSpecFileLocator.new(ENV["FLV_HOME"]).getFixSpecFile(tag8)
@log.debug("quickFixJFile: " + quickFixJFile)
fieldsListener = FieldListener.new
fieldsListener.allFields = @allFields
fieldsListener.messageTypes = @messageTypes
REXML::Document.parse_stream(File.new(quickFixJFile.strip, "r"), fieldsListener)
end
def getFieldName(fieldNumber)
@allFields[fieldNumber.to_s]
end
def getMessageType(tag35)
@messageTypes[tag35.to_s]
end
def getLongestFieldLength()
@allFields["longestNameLength"]
end
end
#test = AllFixFields.new("FIX.4.2")
#puts "field number 7 has name: " + test.getFieldName(7)
#test2 = AllQuickfixFIXFiles.new