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.

61 lines
1.5 KiB

// Protocol Buffers - Google's data interchange format
// Copyright 2023 Google LLC. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// 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
#ifndef UPB_BASE_STRING_VIEW_H_
#define UPB_BASE_STRING_VIEW_H_
#include <string.h>
// Must be last.
#include "upb/port/def.inc"
#define UPB_STRINGVIEW_INIT(ptr, len) \
{ ptr, len }
#define UPB_STRINGVIEW_FORMAT "%.*s"
#define UPB_STRINGVIEW_ARGS(view) (int)(view).size, (view).data
// LINT.IfChange(struct_definition)
typedef struct {
const char* data;
size_t size;
} upb_StringView;
#ifdef __cplusplus
extern "C" {
#endif
UPB_API_INLINE upb_StringView upb_StringView_FromDataAndSize(const char* data,
size_t size) {
upb_StringView ret;
ret.data = data;
ret.size = size;
return ret;
}
UPB_INLINE upb_StringView upb_StringView_FromString(const char* data) {
return upb_StringView_FromDataAndSize(data, strlen(data));
}
UPB_INLINE bool upb_StringView_IsEqual(upb_StringView a, upb_StringView b) {
return a.size == b.size && memcmp(a.data, b.data, a.size) == 0;
}
// LINT.ThenChange(
// GoogleInternalName0,
// //depot/google3/third_party/upb/bits/golang/accessor.go:map_go_string,
// //depot/google3/third_party/upb/bits/typescript/string_view.ts
// )
#ifdef __cplusplus
} /* extern "C" */
#endif
#include "upb/port/undef.inc"
#endif /* UPB_BASE_STRING_VIEW_H_ */