| 1039 | } |
| 1040 | |
| 1041 | absl::string_view LegacyByteString(const ByteString& string, bool stable, |
| 1042 | google::protobuf::Arena* absl_nonnull arena) { |
| 1043 | ABSL_DCHECK(arena != nullptr); |
| 1044 | if (string.empty()) { |
| 1045 | return absl::string_view(); |
| 1046 | } |
| 1047 | const ByteStringKind kind = string.GetKind(); |
| 1048 | if (kind == ByteStringKind::kMedium && string.GetMediumArena() == arena) { |
| 1049 | google::protobuf::Arena* absl_nullable other_arena = string.GetMediumArena(); |
| 1050 | if (other_arena == arena || other_arena == nullptr) { |
| 1051 | // Legacy values do not preserve arena. For speed, we assume the arena is |
| 1052 | // compatible. |
| 1053 | return string.GetMedium(); |
| 1054 | } |
| 1055 | } |
| 1056 | if (stable && kind == ByteStringKind::kSmall) { |
| 1057 | return string.GetSmall(); |
| 1058 | } |
| 1059 | std::string* absl_nonnull result = google::protobuf::Arena::Create<std::string>(arena); |
| 1060 | switch (kind) { |
| 1061 | case ByteStringKind::kSmall: |
| 1062 | result->assign(string.GetSmall()); |
| 1063 | break; |
| 1064 | case ByteStringKind::kMedium: |
| 1065 | result->assign(string.GetMedium()); |
| 1066 | break; |
| 1067 | case ByteStringKind::kLarge: |
| 1068 | absl::CopyCordToString(string.GetLarge(), result); |
| 1069 | break; |
| 1070 | } |
| 1071 | return absl::string_view(*result); |
| 1072 | } |
| 1073 | |
| 1074 | } // namespace cel::common_internal |