0

Make ProtoWrapper accessors const

Bug: 330815376
Change-Id: I92add4a4f980788c29aef98ab59d7adb92101d7f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5873364
Auto-Submit: Joe Mason <joenotcharles@google.com>
Commit-Queue: Joe Mason <joenotcharles@google.com>
Reviewed-by: Alex Gough <ajgo@chromium.org>
Commit-Queue: Alex Gough <ajgo@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1357254}
This commit is contained in:
Joe Mason
2024-09-18 19:12:17 +00:00
committed by Chromium LUCI CQ
parent 21b22f8fc5
commit a759465ee9
2 changed files with 4 additions and 4 deletions

@@ -42,7 +42,7 @@ ProtoWrapper::ProtoWrapper(base::span<const uint8_t> data,
} }
bool ProtoWrapper::DeserializeToMessage( bool ProtoWrapper::DeserializeToMessage(
google::protobuf::MessageLite& message) { google::protobuf::MessageLite& message) const {
if (!bytes_.has_value()) { if (!bytes_.has_value()) {
return false; return false;
} }

@@ -58,7 +58,7 @@ class COMPONENT_EXPORT(MOJO_BASE_PROTOBUF_SUPPORT) ProtoWrapper {
base::PassKey<ProtoWrapperBytes> passkey); base::PassKey<ProtoWrapperBytes> passkey);
template <IsProtoMessage ProtoMessage> template <IsProtoMessage ProtoMessage>
std::optional<ProtoMessage> As() { std::optional<ProtoMessage> As() const {
ProtoMessage message; ProtoMessage message;
if (DeserializeToMessage(message)) { if (DeserializeToMessage(message)) {
return message; return message;
@@ -71,7 +71,7 @@ class COMPONENT_EXPORT(MOJO_BASE_PROTOBUF_SUPPORT) ProtoWrapper {
// cannot change, the contents might. If you want to unpack the contained // cannot change, the contents might. If you want to unpack the contained
// protobuf Message, use As<T>(); // protobuf Message, use As<T>();
std::optional<base::span<const uint8_t>> byte_span( std::optional<base::span<const uint8_t>> byte_span(
base::PassKey<ProtoWrapperBytes> passkey) { base::PassKey<ProtoWrapperBytes> passkey) const {
if (!is_valid()) { if (!is_valid()) {
return std::nullopt; return std::nullopt;
} }
@@ -94,7 +94,7 @@ class COMPONENT_EXPORT(MOJO_BASE_PROTOBUF_SUPPORT) ProtoWrapper {
// bytes will deserialize to a valid message. // bytes will deserialize to a valid message.
bool is_valid() const { return bytes_.has_value(); } bool is_valid() const { return bytes_.has_value(); }
bool DeserializeToMessage(google::protobuf::MessageLite& message); bool DeserializeToMessage(google::protobuf::MessageLite& message) const;
std::string proto_name_; std::string proto_name_;
std::optional<BigBuffer> bytes_; std::optional<BigBuffer> bytes_;