quickfast 编解码_quickfast解析中国的fastfix包--3

本文介绍了如何使用QuickFast编解码库,并提供了针对中国FastFix包的解析示例。通过修改源代码添加模板ID支持,简化了消息构建过程。同时,文章还展示了几个辅助函数的实现,用于从消息中便捷地提取不同类型的数据,如整数、字符串等。
摘要由CSDN通过智能技术生成

BastEt

2014-4-7 15:43:00

阅读(1913)

评论(0)

编译quickfast,其实很容易就编译出来了,我用的是vc2003,把xerces解析的地方去掉了。

QQ:43791167,有不对或者好的思路,不妨共享。

一般要修改一些地方,比如说加上decoder的设置模板id,在message里加个成员变量templateid,这样会方便不少。

比如这里可能就可以这样写:

Messages::MessageBuilder &

GenericMessageBuilder::startMessage(

const std::string & applicationType,

const std::string & applicationTypeNamespace,

size_t size,

template_id_t tid)

{

message_.reset(new Messages::Message(size));

message_->setApplicationType(applicationType, applicationTypeNamespace);

message_->settid(tid);

return *this;

}

void

Decoder::decodeMessage(

DataSource & source,

Messages::ValueMessageBuilder & messageBuilder)

这里面就可以:

Messages::ValueMessageBuilder & bodyBuilder(

messageBuilder.startMessage(

templatePtr->getApplicationType(),

templatePtr->getApplicationTypeNamespace(),

templatePtr->fieldCount(),

templateId_));

decodeSegmentBody(source, pmap, templatePtr, bodyBuilder);

还有一些简单的助手函数可以帮助解析。

uint64 getUnsignedInteger2(const field_id_t & identity, uint64 defaultvalue=0)const

{

uint64 value;

if(getUnsignedInteger(identity,value))

return value;

else

return defaultvalue;

}

bool getSignedInteger(const field_id_t & identity, int64 & value)const

{

FieldCPtr field;

bool result = getField(identity, field);

if(result)

{

value = field->toSignedInteger();

}

return result;

}

int64 getSignedInteger2(const field_id_t & identity, int64 defaultvalue=0)const

{

int64 value;

if(getSignedInteger(identity,value))

return value;

else

return defaultvalue;

}

bool getDecimal(const field_id_t & identity, Decimal & value)const

{

FieldCPtr field;

bool result = getField(identity, field);

if(result)

{

value = field->toDecimal();

}

return result;

}

double getDecimal2(const field_id_t & identity, double defaultvalue=0.0f)const

{

Decimal value;

if(getDecimal(identity,value))

return value;

else

return defaultvalue;

}

bool getString(const field_id_t & identity, const StringBuffer *& value)const

{

FieldCPtr field;

bool result = getField(identity, field);

if(result)

{

value = &field->toString();

}

return result;

}

std::string getString2(const field_id_t & identity, const char *defaultstr="")const

{

const StringBuffer *value=NULL;

if(getString(identity,value))

return *value;

else

return defaultstr;

}

发表评论

您还没有登录,请[登录]或[注册]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值