Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove google::protobuf::MapKey from google::protobuf::MapIterator #917

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions extensions/protobuf/internal/json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ absl::StatusOr<Json> ProtoSingularFieldToJson(
}
}

absl::StatusOr<JsonString> ProtoMapKeyToJsonString(const google::protobuf::MapKey& key) {
absl::StatusOr<JsonString> ProtoMapKeyToJsonString(
const google::protobuf::MapKeyConstRef& key) {
switch (key.type()) {
case google::protobuf::FieldDescriptor::CPPTYPE_BOOL:
return key.GetBoolValue() ? JsonString("true") : JsonString("false");
Expand Down Expand Up @@ -471,7 +472,7 @@ absl::StatusOr<JsonObject> ProtoMapFieldToJsonObject(
auto begin = MapBegin(*reflection, message, *field);
auto end = MapEnd(*reflection, message, *field);
while (begin != end) {
CEL_ASSIGN_OR_RETURN(auto key, ProtoMapKeyToJsonString(begin.GetKey()));
CEL_ASSIGN_OR_RETURN(auto key, ProtoMapKeyToJsonString(begin.GetKeyRef()));
CEL_ASSIGN_OR_RETURN(
auto value,
ProtoMapValueToJson(converter, field->message_type()->map_value(),
Expand Down
30 changes: 15 additions & 15 deletions extensions/protobuf/internal/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,52 +249,52 @@ namespace {
// -----------------------------------------------------------------------------
// google::protobuf::MapKey -> cel::Value

using ProtoMapKeyToValueConverter = absl::Status (*)(const google::protobuf::MapKey&,
ValueManager&, Value&);
using ProtoMapKeyToValueConverter =
absl::Status (*)(const google::protobuf::MapKeyConstRef&, ValueManager&, Value&);

absl::Status ProtoBoolMapKeyToValueConverter(const google::protobuf::MapKey& key,
absl::Status ProtoBoolMapKeyToValueConverter(const google::protobuf::MapKeyConstRef& key,
ValueManager&, Value& result) {
CEL_RETURN_IF_ERROR(ProtoMapKeyTypeMismatch(
google::protobuf::FieldDescriptor::CPPTYPE_BOOL, key.type()));
result = BoolValue{key.GetBoolValue()};
return absl::OkStatus();
}

absl::Status ProtoInt32MapKeyToValueConverter(const google::protobuf::MapKey& key,
absl::Status ProtoInt32MapKeyToValueConverter(const google::protobuf::MapKeyConstRef& key,
ValueManager&, Value& result) {
CEL_RETURN_IF_ERROR(ProtoMapKeyTypeMismatch(
google::protobuf::FieldDescriptor::CPPTYPE_INT32, key.type()));
result = IntValue{key.GetInt32Value()};
return absl::OkStatus();
}

absl::Status ProtoInt64MapKeyToValueConverter(const google::protobuf::MapKey& key,
absl::Status ProtoInt64MapKeyToValueConverter(const google::protobuf::MapKeyConstRef& key,
ValueManager&, Value& result) {
CEL_RETURN_IF_ERROR(ProtoMapKeyTypeMismatch(
google::protobuf::FieldDescriptor::CPPTYPE_INT64, key.type()));
result = IntValue{key.GetInt64Value()};
return absl::OkStatus();
}

absl::Status ProtoUInt32MapKeyToValueConverter(const google::protobuf::MapKey& key,
ValueManager&, Value& result) {
absl::Status ProtoUInt32MapKeyToValueConverter(
const google::protobuf::MapKeyConstRef& key, ValueManager&, Value& result) {
CEL_RETURN_IF_ERROR(ProtoMapKeyTypeMismatch(
google::protobuf::FieldDescriptor::CPPTYPE_UINT32, key.type()));
result = UintValue{key.GetUInt32Value()};
return absl::OkStatus();
}

absl::Status ProtoUInt64MapKeyToValueConverter(const google::protobuf::MapKey& key,
ValueManager&, Value& result) {
absl::Status ProtoUInt64MapKeyToValueConverter(
const google::protobuf::MapKeyConstRef& key, ValueManager&, Value& result) {
CEL_RETURN_IF_ERROR(ProtoMapKeyTypeMismatch(
google::protobuf::FieldDescriptor::CPPTYPE_UINT64, key.type()));
result = UintValue{key.GetUInt64Value()};
return absl::OkStatus();
}

absl::Status ProtoStringMapKeyToValueConverter(const google::protobuf::MapKey& key,
ValueManager& value_manager,
Value& result) {
absl::Status ProtoStringMapKeyToValueConverter(
const google::protobuf::MapKeyConstRef& key, ValueManager& value_manager,
Value& result) {
CEL_RETURN_IF_ERROR(ProtoMapKeyTypeMismatch(
google::protobuf::FieldDescriptor::CPPTYPE_STRING, key.type()));
result = StringValue{key.GetStringValue()};
Expand Down Expand Up @@ -1192,7 +1192,7 @@ class ParsedProtoMapKeyIterator final : public ValueIterator {
absl::Status Next(ValueManager& value_manager, Value& result) override {
Value scratch;
CEL_RETURN_IF_ERROR(
map_key_to_value_(begin_.GetKey(), value_manager, result));
map_key_to_value_(begin_.GetKeyRef(), value_manager, result));
++begin_;
return absl::OkStatus();
}
Expand Down Expand Up @@ -1267,7 +1267,7 @@ class ParsedProtoMapValueInterface
Value key;
while (begin != end) {
CEL_RETURN_IF_ERROR(
map_key_to_value_(begin.GetKey(), value_manager, key));
map_key_to_value_(begin.GetKeyRef(), value_manager, key));
CEL_RETURN_IF_ERROR(builder->Add(std::move(key)));
++begin;
}
Expand All @@ -1283,7 +1283,7 @@ class ParsedProtoMapValueInterface
Value value;
while (begin != end) {
CEL_RETURN_IF_ERROR(
map_key_to_value_(begin.GetKey(), value_manager, key));
map_key_to_value_(begin.GetKeyRef(), value_manager, key));
CEL_RETURN_IF_ERROR(map_value_to_value_(shared_from_this(), field_,
begin.GetValueRef(),
value_manager, value));
Expand Down
2 changes: 1 addition & 1 deletion extensions/protobuf/internal/struct.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ absl::StatusOr<Json> DynamicStructProtoToJson(const google::protobuf::Message& m
CEL_ASSIGN_OR_RETURN(
auto value,
DynamicValueProtoToJson(map_begin.GetValueRef().GetMessageValue()));
builder.insert_or_assign(absl::Cord(map_begin.GetKey().GetStringValue()),
builder.insert_or_assign(absl::Cord(map_begin.GetKeyRef().GetStringValue()),
std::move(value));
}
return std::move(builder).Build();
Expand Down