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.
47 lines
1.1 KiB
47 lines
1.1 KiB
1 year ago
|
// Protocol Buffers - Google's data interchange format
|
||
|
// Copyright 2023 Google LLC. All rights reserved.
|
||
|
//
|
||
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
|
||
3 years ago
|
|
||
12 months ago
|
#ifndef UPB_BASE_INTERNAL_ENDIAN_H_
|
||
|
#define UPB_BASE_INTERNAL_ENDIAN_H_
|
||
3 years ago
|
|
||
1 year ago
|
#include <stdint.h>
|
||
|
|
||
3 years ago
|
// Must be last.
|
||
1 year ago
|
#include "upb/port/def.inc"
|
||
3 years ago
|
|
||
2 years ago
|
#ifdef __cplusplus
|
||
|
extern "C" {
|
||
|
#endif
|
||
|
|
||
12 months ago
|
UPB_INLINE bool upb_IsLittleEndian(void) {
|
||
12 months ago
|
const int x = 1;
|
||
2 years ago
|
return *(char*)&x == 1;
|
||
3 years ago
|
}
|
||
|
|
||
12 months ago
|
UPB_INLINE uint32_t upb_BigEndian32(uint32_t val) {
|
||
|
if (upb_IsLittleEndian()) return val;
|
||
3 years ago
|
|
||
2 years ago
|
return ((val & 0xff) << 24) | ((val & 0xff00) << 8) |
|
||
|
((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24);
|
||
3 years ago
|
}
|
||
|
|
||
12 months ago
|
UPB_INLINE uint64_t upb_BigEndian64(uint64_t val) {
|
||
|
if (upb_IsLittleEndian()) return val;
|
||
3 years ago
|
|
||
12 months ago
|
const uint64_t hi = ((uint64_t)upb_BigEndian32((uint32_t)val)) << 32;
|
||
|
const uint64_t lo = upb_BigEndian32((uint32_t)(val >> 32));
|
||
|
return hi | lo;
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
#ifdef __cplusplus
|
||
|
} /* extern "C" */
|
||
|
#endif
|
||
3 years ago
|
|
||
1 year ago
|
#include "upb/port/undef.inc"
|
||
2 years ago
|
|
||
12 months ago
|
#endif /* UPB_BASE_INTERNAL_ENDIAN_H_ */
|