From fc10098a84d73a97470c08b34b5b0d11a4aa38ad Mon Sep 17 00:00:00 2001 From: Kuat Date: Mon, 7 Oct 2024 14:10:49 -0700 Subject: [PATCH] stream info: add bool string serlalizer (#36451) Change-Id: I2065f5ed863ca4b6b439f00dc39de0dcdbe2eb4c Commit Message: add missing serializer for bool object. I discovered this gap while using Wasm `get_property`. Risk Level: low Testing: yes Signed-off-by: Kuat Yessenov --- source/common/stream_info/bool_accessor_impl.h | 4 ++++ test/common/stream_info/bool_accessor_impl_test.cc | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/source/common/stream_info/bool_accessor_impl.h b/source/common/stream_info/bool_accessor_impl.h index 868bfefab953..8de1563fae48 100644 --- a/source/common/stream_info/bool_accessor_impl.h +++ b/source/common/stream_info/bool_accessor_impl.h @@ -19,6 +19,10 @@ class BoolAccessorImpl : public BoolAccessor { return message; } + absl::optional serializeAsString() const override { + return value_ ? "true" : "false"; + } + // From BoolAccessor. bool value() const override { return value_; } diff --git a/test/common/stream_info/bool_accessor_impl_test.cc b/test/common/stream_info/bool_accessor_impl_test.cc index dcc8c5ccc9f6..4f0845f05e65 100644 --- a/test/common/stream_info/bool_accessor_impl_test.cc +++ b/test/common/stream_info/bool_accessor_impl_test.cc @@ -22,6 +22,12 @@ TEST(BoolAccessorImplTest, TestProto) { EXPECT_NE(nullptr, message); } +TEST(BoolAccessorImplTest, TestString) { + BoolAccessorImpl accessor(true); + auto str = accessor.serializeAsString(); + EXPECT_EQ("true", str); +} + } // namespace } // namespace StreamInfo } // namespace Envoy