Protocol Buffers - Google's data interchange format (grpc依赖)
https://developers.google.com/protocol-buffers/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.3 KiB
51 lines
1.3 KiB
1 year ago
|
// Protocol Buffers - Google's data interchange format
|
||
|
// Copyright 2023 Google LLC. All rights reserved.
|
||
4 years ago
|
//
|
||
1 year ago
|
// Use of this source code is governed by a BSD-style
|
||
|
// license that can be found in the LICENSE file or at
|
||
|
// https://developers.google.com/open-source/licenses/bsd
|
||
5 years ago
|
|
||
1 year ago
|
#ifndef UPB_BASE_STATUS_HPP_
|
||
|
#define UPB_BASE_STATUS_HPP_
|
||
5 years ago
|
|
||
1 year ago
|
#include "upb/base/status.h"
|
||
5 years ago
|
|
||
|
namespace upb {
|
||
|
|
||
|
class Status {
|
||
|
public:
|
||
3 years ago
|
Status() { upb_Status_Clear(&status_); }
|
||
5 years ago
|
|
||
3 years ago
|
upb_Status* ptr() { return &status_; }
|
||
5 years ago
|
|
||
|
// Returns true if there is no error.
|
||
3 years ago
|
bool ok() const { return upb_Status_IsOk(&status_); }
|
||
5 years ago
|
|
||
|
// Guaranteed to be NULL-terminated.
|
||
3 years ago
|
const char* error_message() const {
|
||
|
return upb_Status_ErrorMessage(&status_);
|
||
|
}
|
||
5 years ago
|
|
||
|
// The error message will be truncated if it is longer than
|
||
3 years ago
|
// _kUpb_Status_MaxMessage-4.
|
||
|
void SetErrorMessage(const char* msg) {
|
||
|
upb_Status_SetErrorMessage(&status_, msg);
|
||
|
}
|
||
|
void SetFormattedErrorMessage(const char* fmt, ...) {
|
||
5 years ago
|
va_list args;
|
||
|
va_start(args, fmt);
|
||
3 years ago
|
upb_Status_VSetErrorFormat(&status_, fmt, args);
|
||
5 years ago
|
va_end(args);
|
||
|
}
|
||
|
|
||
|
// Resets the status to a successful state with no message.
|
||
3 years ago
|
void Clear() { upb_Status_Clear(&status_); }
|
||
5 years ago
|
|
||
|
private:
|
||
3 years ago
|
upb_Status status_;
|
||
5 years ago
|
};
|
||
|
|
||
|
} // namespace upb
|
||
|
|
||
1 year ago
|
#endif // UPB_BASE_STATUS_HPP_
|