forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
- Loading branch information
1 parent
0af0446
commit 55a65b7
Showing
10 changed files
with
121 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
#include "envoy/common/pure.h" | ||
#include "envoy/stream_info/filter_state.h" | ||
|
||
namespace Envoy { | ||
namespace StreamInfo { | ||
|
||
/** | ||
* A FilterState object that tracks a single uint64_t value. | ||
*/ | ||
class UInt64Accessor : public FilterState::Object { | ||
public: | ||
/** | ||
* Increments the tracked value by 1. | ||
*/ | ||
virtual void increment() PURE; | ||
|
||
/** | ||
* @return the tracked value. | ||
*/ | ||
virtual uint64_t value() const PURE; | ||
}; | ||
|
||
} // namespace StreamInfo | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include "envoy/stream_info/uint64_accessor.h" | ||
|
||
namespace Envoy { | ||
namespace StreamInfo { | ||
|
||
/* | ||
* A FilterState object that tracks a single uint64_t value. | ||
*/ | ||
class UInt64AccessorImpl : public UInt64Accessor { | ||
public: | ||
UInt64AccessorImpl(uint64_t value) : value_(value) {} | ||
|
||
// From FilterState::Object | ||
ProtobufTypes::MessagePtr serializeAsProto() const override { | ||
auto message = std::make_unique<ProtobufWkt::UInt64Value>(); | ||
message->set_value(value_); | ||
return message; | ||
} | ||
|
||
// From UInt64Accessor. | ||
void increment() override { value_++; } | ||
uint64_t value() const override { return value_; } | ||
|
||
private: | ||
uint64_t value_; | ||
}; | ||
|
||
} // namespace StreamInfo | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "source/common/stream_info/uint64_accessor_impl.h" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
namespace Envoy { | ||
namespace StreamInfo { | ||
namespace { | ||
|
||
TEST(UInt64AccessorImplTest, ConstructorInitsValue) { | ||
uint64_t init_value = 0xdeadbeefdeadbeef; | ||
UInt64AccessorImpl accessor(init_value); | ||
EXPECT_EQ(init_value, accessor.value()); | ||
} | ||
|
||
TEST(UInt64AccessorImplTest, IncrementValue) { | ||
uint64_t init_value = 0xdeadbeefdeadbeef; | ||
UInt64AccessorImpl accessor(init_value); | ||
accessor.increment(); | ||
|
||
EXPECT_EQ(0xdeadbeefdeadbef0, accessor.value()); | ||
} | ||
|
||
TEST(UInt64AccessorImplTest, TestProto) { | ||
uint64_t init_value = 0xdeadbeefdeadbeef; | ||
UInt64AccessorImpl accessor(init_value); | ||
auto message = accessor.serializeAsProto(); | ||
EXPECT_NE(nullptr, message); | ||
|
||
auto* uint64_struct = dynamic_cast<ProtobufWkt::UInt64Value*>(message.get()); | ||
EXPECT_NE(nullptr, uint64_struct); | ||
EXPECT_EQ(init_value, uint64_struct->value()); | ||
} | ||
|
||
} // namespace | ||
} // namespace StreamInfo | ||
} // namespace Envoy |