|
Boost Users : |
Subject: Re: [Boost-users] Using boost Barser to extract data from string
From: Igor R (boost.lists_at_[hidden])
Date: 2011-11-14 07:07:13
>>>> I want to write parser for data I receive from a stock exchange server.
>>>> There is no delimeter that define different fields in buffer I receive.
>>>> However, it is provided in exchange spec's start and of each field.
>>>> How should I write parser for data I recveive? I am new to parser
>>>> consept and apprecite your suggestion.
>>>> I am putting following example data string just to insist my scenario
>>>>
>>>> Data my application recveive:
>>>> 1001TXPASSWORDSESSION1N
>>>>
>>>> I need to decode it(as per spec) as:
>>>> Messate type: 1001
>>>> UserID:Â Â Â Â Â Â Â Â Â Â Â TX
>>>> password:Â Â Â Â Â Â Â PASSWORD
>>>> session:Â Â Â Â Â Â Â Â Â Â SESSION
>>>> data:Â Â Â Â Â Â Â Â Â Â Â Â Â Â N
>>>>
>>>> How should I be doing it?
#include <boost/spirit/include/qi.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
using std::string;
struct message
{
int type_;
string userID_, password_, session_;
char data_;
};
BOOST_FUSION_ADAPT_STRUCT
(
message,
(int, type_)
(string, userID_)
(string, password_)
(string, session_)
(char, data_)
)
int main()
{
namespace qi = boost::spirit::qi;
using qi::char_;
using qi::repeat;
string in = "1001TXPASSWORDSESSION1N";
message out;
bool res = qi::parse(in.begin(), in.end(), qi::int_ >>
repeat(2)[char_] >> repeat(8)[char_] >> repeat(8)[char_] >> char_,
out);
}
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net