Use the XMLMessageTemplateLoader to load template from an XML template file or other XML input stream source.
InputStream templateSource = new FileInputStream("templates.xml"); MessageTemplateLoader templateLoader = new XMLMessageTemplateLoader(); MessageTemplate[] templates = templateLoader.load(templateSource); |
See also:
Scalar Fields
Singleton pre-defined types and operators are defined in the classes Type and Operator. Use these to construct scalar fields. An optional unsigned integer field named "quantity" with a copy operator can be defined as:
Scalar quantity = new Scalar("quantity", Type.U32, Operator.COPY, ScalarValue.UNDEFINED, true); |
A field with a default value can be set up as:
Scalar compid = new Scalar("cid", Type.STRING, Operator.CONSTANT, new StringValue("openfast"), false); |
Group Fields
To create a quote group with two scalars bid and ask
Scalar bid = new Scalar("bid", Type.DECIMAL, Operator.DELTA, ScalarValue.UNDEFINED, false); Scalar ask = new Scalar("ask", Type.DECIMAL, Operator.DELTA, ScalarValue.UNDEFINED, false); Field[] fields = new Field[] { bid, ask }; Group quote = new Group("quote", fields, false); |
Sequence Fields
To create a sequence of parties
Scalar name = new Scalar("name", Type.STRING, Operator.COPY, ScalarValue.UNDEFINED, false); Scalar id = new Scalar("id", Type.STRING, Operator.COPY, ScalarValue.UNDEFINED, false); Field[] fields = new Field[] { name, id }; Sequence parties = new Sequence("parties", fields, false); |
Message Template
Putting it all together:
Field[] fields = new Field[] { compid, quote, parties }; MessageTemplate contractTemplate = new MessageTemplate("contract", fields); |
To create an input stream and register a single template:
InputStream fastEncodedStream = new FileInputStream("marketdata.fast"); MessageInputStream messageIn = new MessageInputStream(fastEncodedStream); messageIn.registerTemplate(63, marketDataTemplate); |
Output to file:
OutputStream out = new FileOutputStream("marketdata.fast"); MessageOutputStream messageOut = new MessageOutputStream(fastStream); messageOut.registerTemplate(63, marketDataTemplate); |
Reading messages:
Message message = messageIn.readMessage(); String compId = message.getString("compid"); // By name int value = message.getLong(2); // By index |
Creating messages:
Message message = new Message(contractTemplate); message.setString("compid", "openfast"); // by name message.setInteger(2, 124); // by index messageOut.writeMessage(message); |
See also: