Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Refactor methods in proto3's AnyMetadata implementation.
Browse files Browse the repository at this point in the history
This is a small refactor to make some future changes easier.

PiperOrigin-RevId: 664879351
  • Loading branch information
tonyliaoss authored and copybara-github committed Aug 19, 2024
1 parent f5f94f3 commit 86a2463
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/google/protobuf/any_lite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ std::string GetTypeUrl(absl::string_view message_name,
}
}

bool EndsWithTypeName(absl::string_view type_url, absl::string_view type_name) {
return type_url.size() > type_name.size() &&
type_url[type_url.size() - type_name.size() - 1] == '/' &&
absl::EndsWith(type_url, type_name);
}

const char kAnyFullTypeName[] = "google.protobuf.Any";
const char kTypeGoogleApisComPrefix[] = "type.googleapis.com/";
const char kTypeGoogleProdComPrefix[] = "type.googleprod.com/";
Expand All @@ -50,10 +56,7 @@ bool AnyMetadata::InternalUnpackTo(absl::string_view type_name,
}

bool AnyMetadata::InternalIs(absl::string_view type_name) const {
absl::string_view type_url = type_url_->Get();
return type_url.size() >= type_name.size() + 1 &&
type_url[type_url.size() - type_name.size() - 1] == '/' &&
absl::EndsWith(type_url, type_name);
return EndsWithTypeName(type_url_->Get(), type_name);
}

bool ParseAnyTypeUrl(absl::string_view type_url, std::string* url_prefix,
Expand Down

0 comments on commit 86a2463

Please sign in to comment.