#ifndef __WireFormats_h_ #define __WireFormats_h_ /* This was inspired by ../generate_alerts/WireFormats.[Ch]. There is no need * to be compatible with that file. * * ../generate_alerts/WireFormats.* was only used by * ../generate_alerts/ProxyData.*. In this incarnation we don't bother with * the WireTos or WireL1 data structures. That old code would copy the fields * one at a time to the WireTos or WireL1 data structures, then just copy the * bytes from the Wire* data structure to the wire. In this new code we read * directly from the L1Data or TosData structure and write directly to a * string, which is common when using marshal() and unmarshal(). * * Currently we are focused on the 24 hour server that will handle crypto- * currencies. However, ideally we'd want these to work for normal equities, * too. Some software might not know or care which data it is looking at, and * some might even listen to multiple data sources and multiple data types at * once. */ #include #include #include "../shared/MiscSupport.h" #include "../fast_alert_search/history_server/Marshal.h" #include "../generate_alerts/data_framework/GenericTosData.h" #include "../generate_alerts/data_framework/GenericL1Data.h" inline void marshal(std::string &destination, L1Data const &value) { marshal(destination, value.bidPrice); marshal(destination, value.bidSize); marshal(destination, value.bidExchange); marshal(destination, value.askPrice); marshal(destination, value.askSize); marshal(destination, value.askExchange); }; inline void unmarshal(std::string const &source, size_t &offset, L1Data &value) { try { unmarshal(source, offset, value.bidPrice); unmarshal(source, offset, value.bidSize); unmarshal(source, offset, value.bidExchange); unmarshal(source, offset, value.askPrice); unmarshal(source, offset, value.askSize); unmarshal(source, offset, value.askExchange); } catch (...) { value.clear(); throw; } } inline void marshal(std::string &destination, TosData const &value) { marshal(destination, value.price); marshal(destination, value.time); marshal(destination, value.size); marshal(destination, value.exchange); marshal(destination, value.formT, value.updatesLast, value.newPrint); marshal(destination, value.todaysClose); marshal(destination, value.volume); marshal(destination, value.open); marshal(destination, value.high); marshal(destination, value.low); }; inline void unmarshal(std::string const &source, size_t &offset, TosData &value) { try { unmarshal(source, offset, value.price); unmarshal(source, offset, value.time); unmarshal(source, offset, value.size); unmarshal(source, offset, value.exchange); unmarshal(source, offset, value.formT, value.updatesLast, value.newPrint); unmarshal(source, offset, value.todaysClose); unmarshal(source, offset, value.volume); unmarshal(source, offset, value.open); unmarshal(source, offset, value.high); unmarshal(source, offset, value.low); } catch (...) { value.clear(); throw; } } // This seems pretty standard on modern Linux systems. I added this mostly as // a comment in case we port this to another platform. static_assert(sizeof(time_t) == sizeof(int64_t), "time_t should be a 64 bit numbert."); #endif