namespace FbMsg; enum MsgType: uint { Unknown = 0, LoginReqType = 101, LoginRspType =…
- User
namespace FbMsg;
enum MsgType: uint {
Unknown = 0, LoginReqType = 101, LoginRspType = 102, EntrustType = 103, EntrustRtnType = 104, TradeRtnType = 105, QryFundAccType = 106, QryFundAccRspType = 107, QryOrdersType = 108, QryOrdersRspType = 109, QryTradesType = 110, QryTradesRspType = 111, QryPositionsType = 112, QryPositionsRspType = 113, CancelOrderType = 114, CancelOrderRtnType = 115, ErrorInfoType = 116, QryShareHolderType = 117, QryShareHolderRspType = 118, HeartBeatType = 119, HeartBeatTypeRspType = 120, AgentRegisterType = 121, AgentRegisterRspType = 122 } table Header { Msgtype: MsgType; MsgLength: uint; ChannelId: uint; AccountId: uint; ClientId: uint; }table LoginReq { ChannelId: string; AccountId: string; Password: string; }
table LoginRsp { ChannelId: string; AccountId: string; TradingDay: string; LoginTime: string; MaxLocalId: uint32; }
table Order { ChannelId: string; ExchangeId: string; InstrumentId: string; AccountId: string; OrderSysId: string; Volume: long; VolumeLeft: long; VolumeTraded: long; LimitPrice: double; TradeAmount: double; BuyOrSell: byte; EnumBuySell: byte; HedgeFlag: byte; OrderPriceType: byte; OpenOrClose: byte; OrderStatus: byte; InsertTime: string; LocalInsertTime: string; OrderId: string; OrigOrderSysId: string; OrigOrderId: string; StatusMsg: string; Trader: string; }
table Trade { ChannelId: string; ExchangeId: string; InstrumentId: string; AccountId: string; OrderSysId: string; OrderId: string; TradeId: string; Price: double; Volume: long; TradeTime: string; BuyOrSell: byte; HedgeFlag: byte; OpenOrClose: byte; UpdateTime: string; Trader: string; }
table FundAccount { ChannelId: string; AccountId: string; Available: double; Balance: double; UpdateTime: string; }
table Position { ChannelId: string; AccountId: string; ExchangeId: string; InstrumentId: string; Name: string; Volume: long; EnableVolume: long; YdVolume: long; TdVolume: long; AvgPrice: double; BuyOrSell: byte; HedgeFlag: byte; UpdateTime: string; }
table ErrorInfo { ChannelId: string; AccountId: string; ErrorId: uint; ErrorMsg: string; UpdateTime: string; }
table QryReq { ChannelId: string; AccountId: string; }
table ShareHolder { ChannelId: string; AccountId: string; ExchangeId: string; ShareHolderId: string; ShareHolderName: string; UpdateTime: string; }
table HeartBeat { ChannelId: string; AccountId: string; LastTime: string; ErrorId: uint; ErrorMsg: string; }
//伪代码
// 发送(消息发送序列) // 1.target_id // 2.msg(header+body)
// 接收(消息接收序列) // 1.msg(hear+body)
class PackMsg { public: PackMsg() :m_msgLength(0) { m_buffer = new uchar_t[10240]; }
~PackMsg() { if(m_buffer) delete m_buffer; } void PackMsg::pack(Header *header, uint8_t *msg, int msg_size) { std::memcpy(m_buffer, header, sizeof(Header)); std::memcpy(m_buffer+sizeof(Header), msg, msg_size); m_msgLength = msg_size + sizeof(Header); } void PackMsg::pack(Header *header) { std::memcpy(m_buffer, header, sizeof(Header)); m_msgLength = sizeof(Header); } uchar_t *PackMsg::getPackMsg() { return m_buffer; } uint32_t PackMsg::getPackMsgLength() { return m_msgLength; } - Assistant
- User
实现 GetHeaderBytes
- Assistant
- User
只读的 不能这样实例化var header = new Header { Msgtype = MsgType.HeartBeatType, MsgLength = (uint)(sizeof(Header) + builder.Offset), ChannelId = 101, AccountId = 12345, ClientId = 67890 };
- Assistant
If the
Headerclass or struct is marked as read-only and its properties do not have set accessors, you cannot use an object initializer to set its properties in the way you've shown. Instead, you would typically need to provide values for these properties within a constructor if they are read-only.Here's an example of how you might modify the
Headerdefinition to include a constructor, or how you might instantiate it using existing constructors if it’s defined properly: