From 0f15f2c62eeb1eb59390e3b52763e92ca2e9e294 Mon Sep 17 00:00:00 2001 From: fasiondog Date: Thu, 2 Nov 2023 02:30:28 +0800 Subject: [PATCH] upgrade flatbuffers --- hikyuu/flat/Spot.py | 210 +++++++++- hikyuu/flat/SpotList.py | 71 +++- hikyuu_cpp/hikyuu/GlobalInitializer.cpp | 2 - .../hikyuu/global/agent/spot_generated.h | 389 ++++++++++++++---- xmake.lua | 2 +- 5 files changed, 588 insertions(+), 86 deletions(-) diff --git a/hikyuu/flat/Spot.py b/hikyuu/flat/Spot.py index 6e1958aa..832065e7 100644 --- a/hikyuu/flat/Spot.py +++ b/hikyuu/flat/Spot.py @@ -10,12 +10,16 @@ class Spot(object): __slots__ = ['_tab'] @classmethod - def GetRootAsSpot(cls, buf, offset): + def GetRootAs(cls, buf, offset=0): n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) x = Spot() x.Init(buf, n + offset) return x + @classmethod + def GetRootAsSpot(cls, buf, offset=0): + """This method is deprecated. Please switch to GetRootAs.""" + return cls.GetRootAs(buf, offset) # Spot def Init(self, buf, pos): self._tab = flatbuffers.table.Table(buf, pos) @@ -238,35 +242,239 @@ class Spot(object): return 0.0 def SpotStart(builder): builder.StartObject(31) +def Start(builder): + return SpotStart(builder) def SpotAddMarket(builder, market): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(market), 0) +def AddMarket(builder, market): + return SpotAddMarket(builder, market) def SpotAddCode(builder, code): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(code), 0) +def AddCode(builder, code): + return SpotAddCode(builder, code) def SpotAddName(builder, name): builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) +def AddName(builder, name): + return SpotAddName(builder, name) def SpotAddDatetime(builder, datetime): builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(datetime), 0) +def AddDatetime(builder, datetime): + return SpotAddDatetime(builder, datetime) def SpotAddYesterdayClose(builder, yesterdayClose): builder.PrependFloat64Slot(4, yesterdayClose, 0.0) +def AddYesterdayClose(builder, yesterdayClose): + return SpotAddYesterdayClose(builder, yesterdayClose) def SpotAddOpen(builder, open): builder.PrependFloat64Slot(5, open, 0.0) +def AddOpen(builder, open): + return SpotAddOpen(builder, open) def SpotAddHigh(builder, high): builder.PrependFloat64Slot(6, high, 0.0) +def AddHigh(builder, high): + return SpotAddHigh(builder, high) def SpotAddLow(builder, low): builder.PrependFloat64Slot(7, low, 0.0) +def AddLow(builder, low): + return SpotAddLow(builder, low) def SpotAddClose(builder, close): builder.PrependFloat64Slot(8, close, 0.0) +def AddClose(builder, close): + return SpotAddClose(builder, close) def SpotAddAmount(builder, amount): builder.PrependFloat64Slot(9, amount, 0.0) +def AddAmount(builder, amount): + return SpotAddAmount(builder, amount) def SpotAddVolumn(builder, volumn): builder.PrependFloat64Slot(10, volumn, 0.0) +def AddVolumn(builder, volumn): + return SpotAddVolumn(builder, volumn) def SpotAddBid1(builder, bid1): builder.PrependFloat64Slot(11, bid1, 0.0) +def AddBid1(builder, bid1): + return SpotAddBid1(builder, bid1) def SpotAddBid1Amount(builder, bid1Amount): builder.PrependFloat64Slot(12, bid1Amount, 0.0) +def AddBid1Amount(builder, bid1Amount): + return SpotAddBid1Amount(builder, bid1Amount) def SpotAddBid2(builder, bid2): builder.PrependFloat64Slot(13, bid2, 0.0) +def AddBid2(builder, bid2): + return SpotAddBid2(builder, bid2) def SpotAddBid2Amount(builder, bid2Amount): builder.PrependFloat64Slot(14, bid2Amount, 0.0) +def AddBid2Amount(builder, bid2Amount): + return SpotAddBid2Amount(builder, bid2Amount) def SpotAddBid3(builder, bid3): builder.PrependFloat64Slot(15, bid3, 0.0) +def AddBid3(builder, bid3): + return SpotAddBid3(builder, bid3) def SpotAddBid3Amount(builder, bid3Amount): builder.PrependFloat64Slot(16, bid3Amount, 0.0) +def AddBid3Amount(builder, bid3Amount): + return SpotAddBid3Amount(builder, bid3Amount) def SpotAddBid4(builder, bid4): builder.PrependFloat64Slot(17, bid4, 0.0) +def AddBid4(builder, bid4): + return SpotAddBid4(builder, bid4) def SpotAddBid4Amount(builder, bid4Amount): builder.PrependFloat64Slot(18, bid4Amount, 0.0) +def AddBid4Amount(builder, bid4Amount): + return SpotAddBid4Amount(builder, bid4Amount) def SpotAddBid5(builder, bid5): builder.PrependFloat64Slot(19, bid5, 0.0) +def AddBid5(builder, bid5): + return SpotAddBid5(builder, bid5) def SpotAddBid5Amount(builder, bid5Amount): builder.PrependFloat64Slot(20, bid5Amount, 0.0) +def AddBid5Amount(builder, bid5Amount): + return SpotAddBid5Amount(builder, bid5Amount) def SpotAddAsk1(builder, ask1): builder.PrependFloat64Slot(21, ask1, 0.0) +def AddAsk1(builder, ask1): + return SpotAddAsk1(builder, ask1) def SpotAddAsk1Amount(builder, ask1Amount): builder.PrependFloat64Slot(22, ask1Amount, 0.0) +def AddAsk1Amount(builder, ask1Amount): + return SpotAddAsk1Amount(builder, ask1Amount) def SpotAddAsk2(builder, ask2): builder.PrependFloat64Slot(23, ask2, 0.0) +def AddAsk2(builder, ask2): + return SpotAddAsk2(builder, ask2) def SpotAddAsk2Amount(builder, ask2Amount): builder.PrependFloat64Slot(24, ask2Amount, 0.0) +def AddAsk2Amount(builder, ask2Amount): + return SpotAddAsk2Amount(builder, ask2Amount) def SpotAddAsk3(builder, ask3): builder.PrependFloat64Slot(25, ask3, 0.0) +def AddAsk3(builder, ask3): + return SpotAddAsk3(builder, ask3) def SpotAddAsk3Amount(builder, ask3Amount): builder.PrependFloat64Slot(26, ask3Amount, 0.0) +def AddAsk3Amount(builder, ask3Amount): + return SpotAddAsk3Amount(builder, ask3Amount) def SpotAddAsk4(builder, ask4): builder.PrependFloat64Slot(27, ask4, 0.0) +def AddAsk4(builder, ask4): + return SpotAddAsk4(builder, ask4) def SpotAddAsk4Amount(builder, ask4Amount): builder.PrependFloat64Slot(28, ask4Amount, 0.0) +def AddAsk4Amount(builder, ask4Amount): + return SpotAddAsk4Amount(builder, ask4Amount) def SpotAddAsk5(builder, ask5): builder.PrependFloat64Slot(29, ask5, 0.0) +def AddAsk5(builder, ask5): + return SpotAddAsk5(builder, ask5) def SpotAddAsk5Amount(builder, ask5Amount): builder.PrependFloat64Slot(30, ask5Amount, 0.0) +def AddAsk5Amount(builder, ask5Amount): + return SpotAddAsk5Amount(builder, ask5Amount) def SpotEnd(builder): return builder.EndObject() +def End(builder): + return SpotEnd(builder) + +class SpotT(object): + + # SpotT + def __init__(self): + self.market = None # type: str + self.code = None # type: str + self.name = None # type: str + self.datetime = None # type: str + self.yesterdayClose = 0.0 # type: float + self.open = 0.0 # type: float + self.high = 0.0 # type: float + self.low = 0.0 # type: float + self.close = 0.0 # type: float + self.amount = 0.0 # type: float + self.volumn = 0.0 # type: float + self.bid1 = 0.0 # type: float + self.bid1Amount = 0.0 # type: float + self.bid2 = 0.0 # type: float + self.bid2Amount = 0.0 # type: float + self.bid3 = 0.0 # type: float + self.bid3Amount = 0.0 # type: float + self.bid4 = 0.0 # type: float + self.bid4Amount = 0.0 # type: float + self.bid5 = 0.0 # type: float + self.bid5Amount = 0.0 # type: float + self.ask1 = 0.0 # type: float + self.ask1Amount = 0.0 # type: float + self.ask2 = 0.0 # type: float + self.ask2Amount = 0.0 # type: float + self.ask3 = 0.0 # type: float + self.ask3Amount = 0.0 # type: float + self.ask4 = 0.0 # type: float + self.ask4Amount = 0.0 # type: float + self.ask5 = 0.0 # type: float + self.ask5Amount = 0.0 # type: float + + @classmethod + def InitFromBuf(cls, buf, pos): + spot = Spot() + spot.Init(buf, pos) + return cls.InitFromObj(spot) + + @classmethod + def InitFromPackedBuf(cls, buf, pos=0): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos) + return cls.InitFromBuf(buf, pos+n) + + @classmethod + def InitFromObj(cls, spot): + x = SpotT() + x._UnPack(spot) + return x + + # SpotT + def _UnPack(self, spot): + if spot is None: + return + self.market = spot.Market() + self.code = spot.Code() + self.name = spot.Name() + self.datetime = spot.Datetime() + self.yesterdayClose = spot.YesterdayClose() + self.open = spot.Open() + self.high = spot.High() + self.low = spot.Low() + self.close = spot.Close() + self.amount = spot.Amount() + self.volumn = spot.Volumn() + self.bid1 = spot.Bid1() + self.bid1Amount = spot.Bid1Amount() + self.bid2 = spot.Bid2() + self.bid2Amount = spot.Bid2Amount() + self.bid3 = spot.Bid3() + self.bid3Amount = spot.Bid3Amount() + self.bid4 = spot.Bid4() + self.bid4Amount = spot.Bid4Amount() + self.bid5 = spot.Bid5() + self.bid5Amount = spot.Bid5Amount() + self.ask1 = spot.Ask1() + self.ask1Amount = spot.Ask1Amount() + self.ask2 = spot.Ask2() + self.ask2Amount = spot.Ask2Amount() + self.ask3 = spot.Ask3() + self.ask3Amount = spot.Ask3Amount() + self.ask4 = spot.Ask4() + self.ask4Amount = spot.Ask4Amount() + self.ask5 = spot.Ask5() + self.ask5Amount = spot.Ask5Amount() + + # SpotT + def Pack(self, builder): + if self.market is not None: + market = builder.CreateString(self.market) + if self.code is not None: + code = builder.CreateString(self.code) + if self.name is not None: + name = builder.CreateString(self.name) + if self.datetime is not None: + datetime = builder.CreateString(self.datetime) + SpotStart(builder) + if self.market is not None: + SpotAddMarket(builder, market) + if self.code is not None: + SpotAddCode(builder, code) + if self.name is not None: + SpotAddName(builder, name) + if self.datetime is not None: + SpotAddDatetime(builder, datetime) + SpotAddYesterdayClose(builder, self.yesterdayClose) + SpotAddOpen(builder, self.open) + SpotAddHigh(builder, self.high) + SpotAddLow(builder, self.low) + SpotAddClose(builder, self.close) + SpotAddAmount(builder, self.amount) + SpotAddVolumn(builder, self.volumn) + SpotAddBid1(builder, self.bid1) + SpotAddBid1Amount(builder, self.bid1Amount) + SpotAddBid2(builder, self.bid2) + SpotAddBid2Amount(builder, self.bid2Amount) + SpotAddBid3(builder, self.bid3) + SpotAddBid3Amount(builder, self.bid3Amount) + SpotAddBid4(builder, self.bid4) + SpotAddBid4Amount(builder, self.bid4Amount) + SpotAddBid5(builder, self.bid5) + SpotAddBid5Amount(builder, self.bid5Amount) + SpotAddAsk1(builder, self.ask1) + SpotAddAsk1Amount(builder, self.ask1Amount) + SpotAddAsk2(builder, self.ask2) + SpotAddAsk2Amount(builder, self.ask2Amount) + SpotAddAsk3(builder, self.ask3) + SpotAddAsk3Amount(builder, self.ask3Amount) + SpotAddAsk4(builder, self.ask4) + SpotAddAsk4Amount(builder, self.ask4Amount) + SpotAddAsk5(builder, self.ask5) + SpotAddAsk5Amount(builder, self.ask5Amount) + spot = SpotEnd(builder) + return spot diff --git a/hikyuu/flat/SpotList.py b/hikyuu/flat/SpotList.py index 8475b062..19a9c9cc 100644 --- a/hikyuu/flat/SpotList.py +++ b/hikyuu/flat/SpotList.py @@ -10,12 +10,16 @@ class SpotList(object): __slots__ = ['_tab'] @classmethod - def GetRootAsSpotList(cls, buf, offset): + def GetRootAs(cls, buf, offset=0): n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) x = SpotList() x.Init(buf, n + offset) return x + @classmethod + def GetRootAsSpotList(cls, buf, offset=0): + """This method is deprecated. Please switch to GetRootAs.""" + return cls.GetRootAs(buf, offset) # SpotList def Init(self, buf, pos): self._tab = flatbuffers.table.Table(buf, pos) @@ -46,6 +50,71 @@ class SpotList(object): return o == 0 def SpotListStart(builder): builder.StartObject(1) +def Start(builder): + return SpotListStart(builder) def SpotListAddSpot(builder, spot): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(spot), 0) +def AddSpot(builder, spot): + return SpotListAddSpot(builder, spot) def SpotListStartSpotVector(builder, numElems): return builder.StartVector(4, numElems, 4) +def StartSpotVector(builder, numElems): + return SpotListStartSpotVector(builder, numElems) def SpotListEnd(builder): return builder.EndObject() +def End(builder): + return SpotListEnd(builder) +import hikyuu.flat.Spot +try: + from typing import List +except: + pass + +class SpotListT(object): + + # SpotListT + def __init__(self): + self.spot = None # type: List[hikyuu.flat.Spot.SpotT] + + @classmethod + def InitFromBuf(cls, buf, pos): + spotList = SpotList() + spotList.Init(buf, pos) + return cls.InitFromObj(spotList) + + @classmethod + def InitFromPackedBuf(cls, buf, pos=0): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos) + return cls.InitFromBuf(buf, pos+n) + + @classmethod + def InitFromObj(cls, spotList): + x = SpotListT() + x._UnPack(spotList) + return x + + # SpotListT + def _UnPack(self, spotList): + if spotList is None: + return + if not spotList.SpotIsNone(): + self.spot = [] + for i in range(spotList.SpotLength()): + if spotList.Spot(i) is None: + self.spot.append(None) + else: + spot_ = hikyuu.flat.Spot.SpotT.InitFromObj(spotList.Spot(i)) + self.spot.append(spot_) + + # SpotListT + def Pack(self, builder): + if self.spot is not None: + spotlist = [] + for i in range(len(self.spot)): + spotlist.append(self.spot[i].Pack(builder)) + SpotListStartSpotVector(builder, len(self.spot)) + for i in reversed(range(len(self.spot))): + builder.PrependUOffsetTRelative(spotlist[i]) + spot = builder.EndVector() + SpotListStart(builder) + if self.spot is not None: + SpotListAddSpot(builder, spot) + spotList = SpotListEnd(builder) + return spotList diff --git a/hikyuu_cpp/hikyuu/GlobalInitializer.cpp b/hikyuu_cpp/hikyuu/GlobalInitializer.cpp index 9be7dbab..98492a75 100644 --- a/hikyuu_cpp/hikyuu/GlobalInitializer.cpp +++ b/hikyuu_cpp/hikyuu/GlobalInitializer.cpp @@ -78,8 +78,6 @@ void GlobalInitializer::clean() { StockManager::quit(); DataDriverFactory::release(); - nng_closeall(); - #if HKU_ENABLE_HDF5_KDATA H5close(); #endif diff --git a/hikyuu_cpp/hikyuu/global/agent/spot_generated.h b/hikyuu_cpp/hikyuu/global/agent/spot_generated.h index 8a78cfca..3e42707f 100644 --- a/hikyuu_cpp/hikyuu/global/agent/spot_generated.h +++ b/hikyuu_cpp/hikyuu/global/agent/spot_generated.h @@ -6,16 +6,61 @@ #include "flatbuffers/flatbuffers.h" +// Ensure the included flatbuffers.h is the same version as when this file was +// generated, otherwise it may not be compatible. +static_assert(FLATBUFFERS_VERSION_MAJOR == 23 && + FLATBUFFERS_VERSION_MINOR == 1 && + FLATBUFFERS_VERSION_REVISION == 21, + "Non-compatible flatbuffers version included"); + namespace hikyuu { namespace flat { struct Spot; struct SpotBuilder; +struct SpotT; struct SpotList; struct SpotListBuilder; +struct SpotListT; -struct Spot FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { +struct SpotT : public ::flatbuffers::NativeTable { + typedef Spot TableType; + std::string market{}; + std::string code{}; + std::string name{}; + std::string datetime{}; + double yesterday_close = 0.0; + double open = 0.0; + double high = 0.0; + double low = 0.0; + double close = 0.0; + double amount = 0.0; + double volumn = 0.0; + double bid1 = 0.0; + double bid1_amount = 0.0; + double bid2 = 0.0; + double bid2_amount = 0.0; + double bid3 = 0.0; + double bid3_amount = 0.0; + double bid4 = 0.0; + double bid4_amount = 0.0; + double bid5 = 0.0; + double bid5_amount = 0.0; + double ask1 = 0.0; + double ask1_amount = 0.0; + double ask2 = 0.0; + double ask2_amount = 0.0; + double ask3 = 0.0; + double ask3_amount = 0.0; + double ask4 = 0.0; + double ask4_amount = 0.0; + double ask5 = 0.0; + double ask5_amount = 0.0; +}; + +struct Spot FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { + typedef SpotT NativeTableType; typedef SpotBuilder Builder; enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { VT_MARKET = 4, @@ -50,17 +95,17 @@ struct Spot FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { VT_ASK5 = 62, VT_ASK5_AMOUNT = 64 }; - const flatbuffers::String *market() const { - return GetPointer(VT_MARKET); + const ::flatbuffers::String *market() const { + return GetPointer(VT_MARKET); } - const flatbuffers::String *code() const { - return GetPointer(VT_CODE); + const ::flatbuffers::String *code() const { + return GetPointer(VT_CODE); } - const flatbuffers::String *name() const { - return GetPointer(VT_NAME); + const ::flatbuffers::String *name() const { + return GetPointer(VT_NAME); } - const flatbuffers::String *datetime() const { - return GetPointer(VT_DATETIME); + const ::flatbuffers::String *datetime() const { + return GetPointer(VT_DATETIME); } double yesterday_close() const { return GetField(VT_YESTERDAY_CLOSE, 0.0); @@ -143,7 +188,7 @@ struct Spot FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { double ask5_amount() const { return GetField(VT_ASK5_AMOUNT, 0.0); } - bool Verify(flatbuffers::Verifier &verifier) const { + bool Verify(::flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_MARKET) && verifier.VerifyString(market()) && @@ -153,51 +198,54 @@ struct Spot FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { verifier.VerifyString(name()) && VerifyOffset(verifier, VT_DATETIME) && verifier.VerifyString(datetime()) && - VerifyField(verifier, VT_YESTERDAY_CLOSE) && - VerifyField(verifier, VT_OPEN) && - VerifyField(verifier, VT_HIGH) && - VerifyField(verifier, VT_LOW) && - VerifyField(verifier, VT_CLOSE) && - VerifyField(verifier, VT_AMOUNT) && - VerifyField(verifier, VT_VOLUMN) && - VerifyField(verifier, VT_BID1) && - VerifyField(verifier, VT_BID1_AMOUNT) && - VerifyField(verifier, VT_BID2) && - VerifyField(verifier, VT_BID2_AMOUNT) && - VerifyField(verifier, VT_BID3) && - VerifyField(verifier, VT_BID3_AMOUNT) && - VerifyField(verifier, VT_BID4) && - VerifyField(verifier, VT_BID4_AMOUNT) && - VerifyField(verifier, VT_BID5) && - VerifyField(verifier, VT_BID5_AMOUNT) && - VerifyField(verifier, VT_ASK1) && - VerifyField(verifier, VT_ASK1_AMOUNT) && - VerifyField(verifier, VT_ASK2) && - VerifyField(verifier, VT_ASK2_AMOUNT) && - VerifyField(verifier, VT_ASK3) && - VerifyField(verifier, VT_ASK3_AMOUNT) && - VerifyField(verifier, VT_ASK4) && - VerifyField(verifier, VT_ASK4_AMOUNT) && - VerifyField(verifier, VT_ASK5) && - VerifyField(verifier, VT_ASK5_AMOUNT) && + VerifyField(verifier, VT_YESTERDAY_CLOSE, 8) && + VerifyField(verifier, VT_OPEN, 8) && + VerifyField(verifier, VT_HIGH, 8) && + VerifyField(verifier, VT_LOW, 8) && + VerifyField(verifier, VT_CLOSE, 8) && + VerifyField(verifier, VT_AMOUNT, 8) && + VerifyField(verifier, VT_VOLUMN, 8) && + VerifyField(verifier, VT_BID1, 8) && + VerifyField(verifier, VT_BID1_AMOUNT, 8) && + VerifyField(verifier, VT_BID2, 8) && + VerifyField(verifier, VT_BID2_AMOUNT, 8) && + VerifyField(verifier, VT_BID3, 8) && + VerifyField(verifier, VT_BID3_AMOUNT, 8) && + VerifyField(verifier, VT_BID4, 8) && + VerifyField(verifier, VT_BID4_AMOUNT, 8) && + VerifyField(verifier, VT_BID5, 8) && + VerifyField(verifier, VT_BID5_AMOUNT, 8) && + VerifyField(verifier, VT_ASK1, 8) && + VerifyField(verifier, VT_ASK1_AMOUNT, 8) && + VerifyField(verifier, VT_ASK2, 8) && + VerifyField(verifier, VT_ASK2_AMOUNT, 8) && + VerifyField(verifier, VT_ASK3, 8) && + VerifyField(verifier, VT_ASK3_AMOUNT, 8) && + VerifyField(verifier, VT_ASK4, 8) && + VerifyField(verifier, VT_ASK4_AMOUNT, 8) && + VerifyField(verifier, VT_ASK5, 8) && + VerifyField(verifier, VT_ASK5_AMOUNT, 8) && verifier.EndTable(); } + SpotT *UnPack(const ::flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SpotT *_o, const ::flatbuffers::resolver_function_t *_resolver = nullptr) const; + static ::flatbuffers::Offset Pack(::flatbuffers::FlatBufferBuilder &_fbb, const SpotT* _o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr); }; struct SpotBuilder { typedef Spot Table; - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_market(flatbuffers::Offset market) { + ::flatbuffers::FlatBufferBuilder &fbb_; + ::flatbuffers::uoffset_t start_; + void add_market(::flatbuffers::Offset<::flatbuffers::String> market) { fbb_.AddOffset(Spot::VT_MARKET, market); } - void add_code(flatbuffers::Offset code) { + void add_code(::flatbuffers::Offset<::flatbuffers::String> code) { fbb_.AddOffset(Spot::VT_CODE, code); } - void add_name(flatbuffers::Offset name) { + void add_name(::flatbuffers::Offset<::flatbuffers::String> name) { fbb_.AddOffset(Spot::VT_NAME, name); } - void add_datetime(flatbuffers::Offset datetime) { + void add_datetime(::flatbuffers::Offset<::flatbuffers::String> datetime) { fbb_.AddOffset(Spot::VT_DATETIME, datetime); } void add_yesterday_close(double yesterday_close) { @@ -281,24 +329,23 @@ struct SpotBuilder { void add_ask5_amount(double ask5_amount) { fbb_.AddElement(Spot::VT_ASK5_AMOUNT, ask5_amount, 0.0); } - explicit SpotBuilder(flatbuffers::FlatBufferBuilder &_fbb) + explicit SpotBuilder(::flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SpotBuilder &operator=(const SpotBuilder &); - flatbuffers::Offset Finish() { + ::flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = ::flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateSpot( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset market = 0, - flatbuffers::Offset code = 0, - flatbuffers::Offset name = 0, - flatbuffers::Offset datetime = 0, +inline ::flatbuffers::Offset CreateSpot( + ::flatbuffers::FlatBufferBuilder &_fbb, + ::flatbuffers::Offset<::flatbuffers::String> market = 0, + ::flatbuffers::Offset<::flatbuffers::String> code = 0, + ::flatbuffers::Offset<::flatbuffers::String> name = 0, + ::flatbuffers::Offset<::flatbuffers::String> datetime = 0, double yesterday_close = 0.0, double open = 0.0, double high = 0.0, @@ -361,8 +408,8 @@ inline flatbuffers::Offset CreateSpot( return builder_.Finish(); } -inline flatbuffers::Offset CreateSpotDirect( - flatbuffers::FlatBufferBuilder &_fbb, +inline ::flatbuffers::Offset CreateSpotDirect( + ::flatbuffers::FlatBufferBuilder &_fbb, const char *market = nullptr, const char *code = nullptr, const char *name = nullptr, @@ -433,89 +480,269 @@ inline flatbuffers::Offset CreateSpotDirect( ask5_amount); } -struct SpotList FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { +::flatbuffers::Offset CreateSpot(::flatbuffers::FlatBufferBuilder &_fbb, const SpotT *_o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct SpotListT : public ::flatbuffers::NativeTable { + typedef SpotList TableType; + std::vector> spot{}; + SpotListT() = default; + SpotListT(const SpotListT &o); + SpotListT(SpotListT&&) FLATBUFFERS_NOEXCEPT = default; + SpotListT &operator=(SpotListT o) FLATBUFFERS_NOEXCEPT; +}; + +struct SpotList FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { + typedef SpotListT NativeTableType; typedef SpotListBuilder Builder; enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { VT_SPOT = 4 }; - const flatbuffers::Vector> *spot() const { - return GetPointer> *>(VT_SPOT); + const ::flatbuffers::Vector<::flatbuffers::Offset> *spot() const { + return GetPointer> *>(VT_SPOT); } - bool Verify(flatbuffers::Verifier &verifier) const { + bool Verify(::flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_SPOT) && verifier.VerifyVector(spot()) && verifier.VerifyVectorOfTables(spot()) && verifier.EndTable(); } + SpotListT *UnPack(const ::flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SpotListT *_o, const ::flatbuffers::resolver_function_t *_resolver = nullptr) const; + static ::flatbuffers::Offset Pack(::flatbuffers::FlatBufferBuilder &_fbb, const SpotListT* _o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr); }; struct SpotListBuilder { typedef SpotList Table; - flatbuffers::FlatBufferBuilder &fbb_; - flatbuffers::uoffset_t start_; - void add_spot(flatbuffers::Offset>> spot) { + ::flatbuffers::FlatBufferBuilder &fbb_; + ::flatbuffers::uoffset_t start_; + void add_spot(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset>> spot) { fbb_.AddOffset(SpotList::VT_SPOT, spot); } - explicit SpotListBuilder(flatbuffers::FlatBufferBuilder &_fbb) + explicit SpotListBuilder(::flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SpotListBuilder &operator=(const SpotListBuilder &); - flatbuffers::Offset Finish() { + ::flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset(end); + auto o = ::flatbuffers::Offset(end); return o; } }; -inline flatbuffers::Offset CreateSpotList( - flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset>> spot = 0) { +inline ::flatbuffers::Offset CreateSpotList( + ::flatbuffers::FlatBufferBuilder &_fbb, + ::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset>> spot = 0) { SpotListBuilder builder_(_fbb); builder_.add_spot(spot); return builder_.Finish(); } -inline flatbuffers::Offset CreateSpotListDirect( - flatbuffers::FlatBufferBuilder &_fbb, - const std::vector> *spot = nullptr) { - auto spot__ = spot ? _fbb.CreateVector>(*spot) : 0; +inline ::flatbuffers::Offset CreateSpotListDirect( + ::flatbuffers::FlatBufferBuilder &_fbb, + const std::vector<::flatbuffers::Offset> *spot = nullptr) { + auto spot__ = spot ? _fbb.CreateVector<::flatbuffers::Offset>(*spot) : 0; return hikyuu::flat::CreateSpotList( _fbb, spot__); } +::flatbuffers::Offset CreateSpotList(::flatbuffers::FlatBufferBuilder &_fbb, const SpotListT *_o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr); + +inline SpotT *Spot::UnPack(const ::flatbuffers::resolver_function_t *_resolver) const { + auto _o = std::unique_ptr(new SpotT()); + UnPackTo(_o.get(), _resolver); + return _o.release(); +} + +inline void Spot::UnPackTo(SpotT *_o, const ::flatbuffers::resolver_function_t *_resolver) const { + (void)_o; + (void)_resolver; + { auto _e = market(); if (_e) _o->market = _e->str(); } + { auto _e = code(); if (_e) _o->code = _e->str(); } + { auto _e = name(); if (_e) _o->name = _e->str(); } + { auto _e = datetime(); if (_e) _o->datetime = _e->str(); } + { auto _e = yesterday_close(); _o->yesterday_close = _e; } + { auto _e = open(); _o->open = _e; } + { auto _e = high(); _o->high = _e; } + { auto _e = low(); _o->low = _e; } + { auto _e = close(); _o->close = _e; } + { auto _e = amount(); _o->amount = _e; } + { auto _e = volumn(); _o->volumn = _e; } + { auto _e = bid1(); _o->bid1 = _e; } + { auto _e = bid1_amount(); _o->bid1_amount = _e; } + { auto _e = bid2(); _o->bid2 = _e; } + { auto _e = bid2_amount(); _o->bid2_amount = _e; } + { auto _e = bid3(); _o->bid3 = _e; } + { auto _e = bid3_amount(); _o->bid3_amount = _e; } + { auto _e = bid4(); _o->bid4 = _e; } + { auto _e = bid4_amount(); _o->bid4_amount = _e; } + { auto _e = bid5(); _o->bid5 = _e; } + { auto _e = bid5_amount(); _o->bid5_amount = _e; } + { auto _e = ask1(); _o->ask1 = _e; } + { auto _e = ask1_amount(); _o->ask1_amount = _e; } + { auto _e = ask2(); _o->ask2 = _e; } + { auto _e = ask2_amount(); _o->ask2_amount = _e; } + { auto _e = ask3(); _o->ask3 = _e; } + { auto _e = ask3_amount(); _o->ask3_amount = _e; } + { auto _e = ask4(); _o->ask4 = _e; } + { auto _e = ask4_amount(); _o->ask4_amount = _e; } + { auto _e = ask5(); _o->ask5 = _e; } + { auto _e = ask5_amount(); _o->ask5_amount = _e; } +} + +inline ::flatbuffers::Offset Spot::Pack(::flatbuffers::FlatBufferBuilder &_fbb, const SpotT* _o, const ::flatbuffers::rehasher_function_t *_rehasher) { + return CreateSpot(_fbb, _o, _rehasher); +} + +inline ::flatbuffers::Offset CreateSpot(::flatbuffers::FlatBufferBuilder &_fbb, const SpotT *_o, const ::flatbuffers::rehasher_function_t *_rehasher) { + (void)_rehasher; + (void)_o; + struct _VectorArgs { ::flatbuffers::FlatBufferBuilder *__fbb; const SpotT* __o; const ::flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va; + auto _market = _o->market.empty() ? 0 : _fbb.CreateString(_o->market); + auto _code = _o->code.empty() ? 0 : _fbb.CreateString(_o->code); + auto _name = _o->name.empty() ? 0 : _fbb.CreateString(_o->name); + auto _datetime = _o->datetime.empty() ? 0 : _fbb.CreateString(_o->datetime); + auto _yesterday_close = _o->yesterday_close; + auto _open = _o->open; + auto _high = _o->high; + auto _low = _o->low; + auto _close = _o->close; + auto _amount = _o->amount; + auto _volumn = _o->volumn; + auto _bid1 = _o->bid1; + auto _bid1_amount = _o->bid1_amount; + auto _bid2 = _o->bid2; + auto _bid2_amount = _o->bid2_amount; + auto _bid3 = _o->bid3; + auto _bid3_amount = _o->bid3_amount; + auto _bid4 = _o->bid4; + auto _bid4_amount = _o->bid4_amount; + auto _bid5 = _o->bid5; + auto _bid5_amount = _o->bid5_amount; + auto _ask1 = _o->ask1; + auto _ask1_amount = _o->ask1_amount; + auto _ask2 = _o->ask2; + auto _ask2_amount = _o->ask2_amount; + auto _ask3 = _o->ask3; + auto _ask3_amount = _o->ask3_amount; + auto _ask4 = _o->ask4; + auto _ask4_amount = _o->ask4_amount; + auto _ask5 = _o->ask5; + auto _ask5_amount = _o->ask5_amount; + return hikyuu::flat::CreateSpot( + _fbb, + _market, + _code, + _name, + _datetime, + _yesterday_close, + _open, + _high, + _low, + _close, + _amount, + _volumn, + _bid1, + _bid1_amount, + _bid2, + _bid2_amount, + _bid3, + _bid3_amount, + _bid4, + _bid4_amount, + _bid5, + _bid5_amount, + _ask1, + _ask1_amount, + _ask2, + _ask2_amount, + _ask3, + _ask3_amount, + _ask4, + _ask4_amount, + _ask5, + _ask5_amount); +} + +inline SpotListT::SpotListT(const SpotListT &o) { + spot.reserve(o.spot.size()); + for (const auto &spot_ : o.spot) { spot.emplace_back((spot_) ? new hikyuu::flat::SpotT(*spot_) : nullptr); } +} + +inline SpotListT &SpotListT::operator=(SpotListT o) FLATBUFFERS_NOEXCEPT { + std::swap(spot, o.spot); + return *this; +} + +inline SpotListT *SpotList::UnPack(const ::flatbuffers::resolver_function_t *_resolver) const { + auto _o = std::unique_ptr(new SpotListT()); + UnPackTo(_o.get(), _resolver); + return _o.release(); +} + +inline void SpotList::UnPackTo(SpotListT *_o, const ::flatbuffers::resolver_function_t *_resolver) const { + (void)_o; + (void)_resolver; + { auto _e = spot(); if (_e) { _o->spot.resize(_e->size()); for (::flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { if(_o->spot[_i]) { _e->Get(_i)->UnPackTo(_o->spot[_i].get(), _resolver); } else { _o->spot[_i] = std::unique_ptr(_e->Get(_i)->UnPack(_resolver)); }; } } else { _o->spot.resize(0); } } +} + +inline ::flatbuffers::Offset SpotList::Pack(::flatbuffers::FlatBufferBuilder &_fbb, const SpotListT* _o, const ::flatbuffers::rehasher_function_t *_rehasher) { + return CreateSpotList(_fbb, _o, _rehasher); +} + +inline ::flatbuffers::Offset CreateSpotList(::flatbuffers::FlatBufferBuilder &_fbb, const SpotListT *_o, const ::flatbuffers::rehasher_function_t *_rehasher) { + (void)_rehasher; + (void)_o; + struct _VectorArgs { ::flatbuffers::FlatBufferBuilder *__fbb; const SpotListT* __o; const ::flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va; + auto _spot = _o->spot.size() ? _fbb.CreateVector<::flatbuffers::Offset> (_o->spot.size(), [](size_t i, _VectorArgs *__va) { return CreateSpot(*__va->__fbb, __va->__o->spot[i].get(), __va->__rehasher); }, &_va ) : 0; + return hikyuu::flat::CreateSpotList( + _fbb, + _spot); +} + inline const hikyuu::flat::SpotList *GetSpotList(const void *buf) { - return flatbuffers::GetRoot(buf); + return ::flatbuffers::GetRoot(buf); } inline const hikyuu::flat::SpotList *GetSizePrefixedSpotList(const void *buf) { - return flatbuffers::GetSizePrefixedRoot(buf); + return ::flatbuffers::GetSizePrefixedRoot(buf); } inline bool VerifySpotListBuffer( - flatbuffers::Verifier &verifier) { + ::flatbuffers::Verifier &verifier) { return verifier.VerifyBuffer(nullptr); } inline bool VerifySizePrefixedSpotListBuffer( - flatbuffers::Verifier &verifier) { + ::flatbuffers::Verifier &verifier) { return verifier.VerifySizePrefixedBuffer(nullptr); } inline void FinishSpotListBuffer( - flatbuffers::FlatBufferBuilder &fbb, - flatbuffers::Offset root) { + ::flatbuffers::FlatBufferBuilder &fbb, + ::flatbuffers::Offset root) { fbb.Finish(root); } inline void FinishSizePrefixedSpotListBuffer( - flatbuffers::FlatBufferBuilder &fbb, - flatbuffers::Offset root) { + ::flatbuffers::FlatBufferBuilder &fbb, + ::flatbuffers::Offset root) { fbb.FinishSizePrefixed(root); } +inline std::unique_ptr UnPackSpotList( + const void *buf, + const ::flatbuffers::resolver_function_t *res = nullptr) { + return std::unique_ptr(GetSpotList(buf)->UnPack(res)); +} + +inline std::unique_ptr UnPackSizePrefixedSpotList( + const void *buf, + const ::flatbuffers::resolver_function_t *res = nullptr) { + return std::unique_ptr(GetSizePrefixedSpotList(buf)->UnPack(res)); +} + } // namespace flat } // namespace hikyuu diff --git a/xmake.lua b/xmake.lua index aca3e087..e6c138fc 100644 --- a/xmake.lua +++ b/xmake.lua @@ -113,7 +113,7 @@ set_languages("cxx17", "c99") local boost_version = "1.81.0" local hdf5_version = "1.12.2" local fmt_version = "10.0.0" -local flatbuffers_version = "2.0.0" +local flatbuffers_version = "23.1.21" local mysql_version = "8.0.31" if is_plat("windows") or (is_plat("linux", "cross") and is_arch("aarch64", "arm64.*")) then mysql_version = "8.0.21"