#pragma once #include #include #include namespace Proto { // ¹Ì¶¨Ö¡ inline constexpr uint8_t kHead[4] = { 0x11, 0x88, 0x11, 0x88 }; inline constexpr uint8_t kTail = 0x88; // Ö¸ÁîÂë enum : uint16_t { // ÎÕÊÖ CMD_REQ_VERSION = 0x0001, CMD_RSP_VERSION = 0xF001, // µ¥Í¨µÀÔöÁ¿À­È¡ CMD_REQ_SINCE = 0x0101, CMD_RSP_SINCE = 0xF101, // ͳ¼Æ/ͨµÀÁбí CMD_REQ_STATS = 0x0103, CMD_RSP_STATS = 0xF103, // »ų́Áбí CMD_REQ_MACHINES = 0x0104, CMD_RSP_MACHINES = 0xF104, // Õû»ú¶àͨµÀÔöÁ¿À­È¡ CMD_REQ_SINCE_ALL = 0x0105, CMD_RSP_SINCE_ALL = 0xF105, // Åú´ÎÐÅÏ¢ CMD_REQ_BATCH_INFO = 0x0120, CMD_RSP_BATCH_INFO = 0xF120, // ´íÎó CMD_RSP_ERROR = 0xE100, }; // === since* ÇëÇóÀ︽¼Ó batchId µÄ±ê־λ === inline constexpr uint16_t SINCE_FLAG_HAS_BATCH = 0x0001; // ===== Êý¾Ý½á¹¹£¨Á½¶Ë¹²Óã© ===== // 0x0001 / 0xF001 struct ReqVersion { uint32_t dataId = 0; }; struct RspVersion { uint32_t dataId = 0; std::string version; // UTF-8£¬ÀýÈç "1.0.1" }; // 0x0104 / 0xF104 struct MachineInfo { uint32_t id = 0; std::string name; }; struct ReqMachines { uint32_t dataId = 0; }; struct RspMachines { uint32_t dataId = 0; std::vector machines; }; // 0x0103 / 0xF103 struct ReqStats { uint32_t dataId = 0; uint32_t machineId = 0; uint16_t flags = 0; }; struct ChannelStatInfo { uint32_t channelId = 0; uint64_t earliestTs = 0; uint64_t latestTs = 0; uint32_t size = 0; std::string name; // UTF-8 }; struct RspStats { uint32_t dataId = 0; uint32_t machineId = 0; std::vector channels; }; // 0x0101 / 0xF101£¨µ¥Í¨µÀÔöÁ¿£© struct ReqSince { uint32_t dataId = 0; uint32_t machineId = 0; uint32_t channelId = 0; uint64_t sinceTsExclusive = 0; // ms uint16_t maxCount = 1024; uint16_t flags = 0; // °´Î»£¬¼û SINCE_FLAG_HAS_BATCH std::string batchId; // flags & SINCE_FLAG_HAS_BATCH ʱÓÐЧ }; struct SamplePair { uint64_t ts_ms = 0; double value = 0.0; }; struct RspSince { uint32_t dataId = 0; uint32_t machineId = 0; uint32_t channelId = 0; uint64_t lastTsSent = 0; uint8_t more = 0; // ¸ÃͨµÀÊÇ·ñ»¹ÓÐδ·¢ std::vector samples; }; // 0x0105 / 0xF105£¨Õû»ú¶àͨµÀÔöÁ¿£© struct ChannelBlock { uint32_t channelId = 0; uint64_t lastTsSent = 0; // ¸ÃͨµÀ±¾´Î×îºóÑù±¾Ê±¼ä´Á uint8_t more = 0; // ¸ÃͨµÀÊÇ·ñ»¹ÓÐδ·¢ std::vector samples; }; struct ReqSinceAll { uint32_t dataId = 0; uint32_t machineId = 0; uint64_t sinceTsExclusive = 0; // ¶ÔËùÓÐͨµÀͳһ since uint16_t maxPerChannel = 1024; // ÿÌõÇúÏßÉÏÏÞ uint16_t flags = 0; // °´Î»£¬¼û SINCE_FLAG_HAS_BATCH std::string batchId; // flags & SINCE_FLAG_HAS_BATCH ʱÓÐЧ }; struct RspSinceAll { uint32_t dataId = 0; uint32_t machineId = 0; uint8_t moreAny = 0; // ÊÇ·ñ»¹ÓÐÈÎÒâͨµÀÓÐÊ£Óà std::vector blocks; // ¶à¸öͨµÀµÄÔöÁ¿ }; // === Åú´Î״̬ === enum class BatchState : uint8_t { Idle = 0, // Î޻Åú´Î£ºactiveBatchId="", activeStartTs=0, expectedEndTs=0 Active = 1, }; // === ´íÎóÂë === enum class ErrCode : uint16_t { NoActiveBatch = 0x0001, // µ±Ç°Î޻Åú´Î BatchMismatch = 0x0002, // ÇëÇóЯ´øµÄ batchId Ó뵱ǰ»î¶¯Åú´Î²»Ò»Ö }; // 0x0120 / 0xF120£¨Åú´ÎÐÅÏ¢£© struct ReqBatchInfo { uint32_t dataId = 0; uint32_t machineId = 0; }; struct RspBatchInfo { uint32_t dataId = 0; uint32_t machineId = 0; BatchState state = BatchState::Idle; std::string activeBatchId; // state=Idle ʱӦΪ¿Õ uint64_t activeStartTs = 0; uint64_t expectedEndTs = 0; // =0 ±íʾδ֪/Idle }; // 0xE100 ´íÎóÖ¡ struct RspError { uint32_t dataId = 0; uint16_t refCmd = 0; // ³ö´íÇëÇóµÄÖ¸ÁÈç 0x0101/0x0105/0x0120... uint32_t machineId = 0; ErrCode code = ErrCode::NoActiveBatch; std::string message; // ¼ò¶ÌÎı¾ }; } // namespace Proto