]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Take @rgacogne's suggestion and provide ct for initializer list
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 10 Nov 2025 09:46:46 +0000 (10:46 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 10 Nov 2025 11:07:46 +0000 (12:07 +0100)
Signed-off-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
pdns/protozero-trace.hh

index 34c5c489ce6960a0d80aed8f9e005e75e0d30799..1b2fc2b9feda3cfe2073012b3802fcaf99d33b3d 100644 (file)
@@ -229,11 +229,15 @@ struct InstrumentationScope
   static InstrumentationScope decode(protozero::pbf_reader& reader);
 };
 
-constexpr std::array<uint8_t, 16> s_emptyTraceID{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 struct TraceID : public std::array<uint8_t, 16>
 {
   TraceID() :
-    array{s_emptyTraceID} {};
+    array{} {};
+  TraceID(const std::initializer_list<uint8_t>& arg) :
+    array{}
+  {
+    std::copy(arg.begin(), arg.end(), begin());
+  }
 
   [[nodiscard]] std::string toLogString() const;
   friend std::ostream& operator<<(std::ostream& ostrm, const TraceID& val)
@@ -244,7 +248,7 @@ struct TraceID : public std::array<uint8_t, 16>
   static TraceID getRandomTraceID()
   {
     TraceID ret;
-    dns_random(ret.data(), ret.size());
+    ret.makeRandom();
     return ret;
   }
 
@@ -258,12 +262,17 @@ struct TraceID : public std::array<uint8_t, 16>
     this->fill(0);
   }
 };
+const TraceID s_emptyTraceID = {};
 
-constexpr std::array<uint8_t, 8> s_emptySpanID{0, 0, 0, 0, 0, 0, 0, 0};
 struct SpanID : public std::array<uint8_t, 8>
 {
   SpanID() :
-    array{s_emptySpanID} {};
+    array{} {};
+  SpanID(const std::initializer_list<uint8_t>& arg) :
+    array{}
+  {
+    std::copy(arg.begin(), arg.end(), begin());
+  }
 
   [[nodiscard]] std::string toLogString() const;
   friend std::ostream& operator<<(std::ostream& ostrm, const SpanID& val)
@@ -274,7 +283,7 @@ struct SpanID : public std::array<uint8_t, 8>
   static SpanID getRandomSpanID()
   {
     SpanID ret;
-    dns_random(ret.data(), ret.size());
+    ret.makeRandom();
     return ret;
   }
 
@@ -288,6 +297,7 @@ struct SpanID : public std::array<uint8_t, 8>
     this->fill(0);
   }
 };
+const SpanID s_emptySpanID = {};
 
 inline void fill(TraceID& trace, const std::string& data)
 {