0

ブーストスピリットチーバイナリエンディアンパーサーの使い方を勉強しています。ここ基本的な例に従って小さなテストパーサープログラムを作成しますが、正しく機能しません。それは私にmsg: "Error:nomatch"を与えました。

これが私のコードです。

 
    #include "boost/spirit/include/qi.hpp"
    #include "boost/spirit/include/phoenix_core.hpp"
    #include "boost/spirit/include/phoenix_operator.hpp"
    #include "boost/spirit/include/qi_binary.hpp"  // parsing binary data in various endianness

template "<"typename P, typename T> void binary_parser( char const* input, P const& endian_word_type, T& voxel, bool full_match = true) { using boost::spirit::qi::parse; char const* f(input); char const* l(f + strlen(f)); bool result1 = parse(f,l,endian_word_type,voxel); bool result2 =((!full_match) || (f ==l)); if ( result1 && result2) { //doing nothing, parsing data is pass to voxel alreay } else { std::cerr << "Error: not match!!" << std::endl; exit(1); } } typedef boost::uint16_t bs_int16; typedef boost::uint32_t bs_int32; int main ( int argc, char *argv[] ){ namespace qi = boost::spirit::qi; namespace ascii = boost::spirit::ascii; using qi::big_word; using qi::big_dword; boost::uint32_t ui; float uf; binary_parser("\x01\x02\x03\x04",big_word,ui); assert(ui=0x01020304); binary_parser("\x01\x02\x03\x04",big_word,uf); assert(uf=0x01020304); return 0; }

私はほとんど例をコピーしますが、なぜこのバイナリパーサーが機能しないのですか。MacOS10.5.8とgcc4.01コンパイラを使用しています。

4

2 に答える 2

2

パーサーはbig_wordビッグエンディアンワード(16ビット)にbig_dword一致しますが、必要なもの(ビッグエンディアンdword、32ビット)に一致します。しかし、バイナリパーサーの属性としてfloatを使用するのは良い考えではないと思います。期待したものが得られない可能性があります。

于 2010-05-20T20:37:33.040 に答える
0

間違った解析パラメータを使用しました。big_word代わりに使うべきではないbig_dword

于 2010-05-20T16:00:27.443 に答える