From 8ebd99c74ee7e69be7cbe4b83f845ad51b0a8e61 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 27 May 2024 00:21:34 -0400 Subject: [PATCH] Back in enum values for `BuildMode` serializer We don't want to rely on how C assigns numbers for enums in the wire format. Sure, this is totally determined by the ABI, but it obscures the code and makes it harder to safely change the enum definition (should we need to) without accidentally breaking the wire format. --- src/libstore/worker-protocol.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libstore/worker-protocol.cc b/src/libstore/worker-protocol.cc index ed6367c38..4d397ed21 100644 --- a/src/libstore/worker-protocol.cc +++ b/src/libstore/worker-protocol.cc @@ -18,9 +18,9 @@ BuildMode WorkerProto::Serialise::read(const StoreDirConfig & store, { auto temp = readNum(conn.from); switch (temp) { - case bmNormal: return bmNormal; - case bmRepair: return bmRepair; - case bmCheck: return bmCheck; + case 0: return bmNormal; + case 1: return bmRepair; + case 2: return bmCheck; default: throw Error("Invalid build mode"); } } @@ -29,13 +29,13 @@ void WorkerProto::Serialise::write(const StoreDirConfig & store, Work { switch (buildMode) { case bmNormal: - conn.to << uint8_t{bmNormal}; + conn.to << uint8_t{0}; break; case bmRepair: - conn.to << uint8_t{bmRepair}; + conn.to << uint8_t{1}; break; case bmCheck: - conn.to << uint8_t{bmCheck}; + conn.to << uint8_t{2}; break; default: assert(false);