![]() |
|
|||
File indexing completed on 2025-02-22 09:54:31
0001 // Copyright 2019 The Abseil Authors. 0002 // 0003 // Licensed under the Apache License, Version 2.0 (the "License"); 0004 // you may not use this file except in compliance with the License. 0005 // You may obtain a copy of the License at 0006 // 0007 // https://www.apache.org/licenses/LICENSE-2.0 0008 // 0009 // Unless required by applicable law or agreed to in writing, software 0010 // distributed under the License is distributed on an "AS IS" BASIS, 0011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0012 // See the License for the specific language governing permissions and 0013 // limitations under the License. 0014 #ifndef ABSL_STATUS_STATUS_PAYLOAD_PRINTER_H_ 0015 #define ABSL_STATUS_STATUS_PAYLOAD_PRINTER_H_ 0016 0017 #include <string> 0018 0019 #include "absl/base/nullability.h" 0020 #include "absl/strings/cord.h" 0021 #include "absl/strings/string_view.h" 0022 #include "absl/types/optional.h" 0023 0024 namespace absl { 0025 ABSL_NAMESPACE_BEGIN 0026 namespace status_internal { 0027 0028 // By default, `Status::ToString` and `operator<<(Status)` print a payload by 0029 // dumping the type URL and the raw bytes. To help debugging, we provide an 0030 // extension point, which is a global printer function that can be set by users 0031 // to specify how to print payloads. The function takes the type URL and the 0032 // payload as input, and should return a valid human-readable string on success 0033 // or `absl::nullopt` on failure (in which case it falls back to the default 0034 // approach of printing the raw bytes). 0035 // NOTE: This is an internal API and the design is subject to change in the 0036 // future in a non-backward-compatible way. Since it's only meant for debugging 0037 // purpose, you should not rely on it in any critical logic. 0038 using StatusPayloadPrinter = absl::Nullable<absl::optional<std::string> (*)( 0039 absl::string_view, const absl::Cord&)>; 0040 0041 // Sets the global payload printer. Only one printer should be set per process. 0042 // If multiple printers are set, it's undefined which one will be used. 0043 void SetStatusPayloadPrinter(StatusPayloadPrinter); 0044 0045 // Returns the global payload printer if previously set, otherwise `nullptr`. 0046 StatusPayloadPrinter GetStatusPayloadPrinter(); 0047 0048 } // namespace status_internal 0049 ABSL_NAMESPACE_END 0050 } // namespace absl 0051 0052 #endif // ABSL_STATUS_STATUS_PAYLOAD_PRINTER_H_
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |