Sha256: 6410ff5604aad50004667377586902ffc7166bba277220eb439874bd00aed411

Contents?: true

Size: 1.1 KB

Versions: 17

Compression:

Stored size: 1.1 KB

Contents

// Protocol Buffers - Google's data interchange format
// Copyright 2023 Google LLC.  All rights reserved.
//
// 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_INTERNAL_ENDIAN_H_
#define UPB_BASE_INTERNAL_ENDIAN_H_

#include <stdint.h>

// Must be last.
#include "upb/port/def.inc"

#ifdef __cplusplus
extern "C" {
#endif

UPB_INLINE bool upb_IsLittleEndian(void) {
  const int x = 1;
  return *(char*)&x == 1;
}

UPB_INLINE uint32_t upb_BigEndian32(uint32_t val) {
  if (upb_IsLittleEndian()) return val;

  return ((val & 0xff) << 24) | ((val & 0xff00) << 8) |
         ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24);
}

UPB_INLINE uint64_t upb_BigEndian64(uint64_t val) {
  if (upb_IsLittleEndian()) return val;

  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;
}

#ifdef __cplusplus
} /* extern "C" */
#endif

#include "upb/port/undef.inc"

#endif /* UPB_BASE_INTERNAL_ENDIAN_H_ */

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
grpc-1.70.1 third_party/upb/upb/base/internal/endian.h
grpc-1.69.0 third_party/upb/upb/base/internal/endian.h
grpc-1.69.0.pre1 third_party/upb/upb/base/internal/endian.h
grpc-1.68.1 third_party/upb/upb/base/internal/endian.h
grpc-1.67.0 third_party/upb/upb/base/internal/endian.h
grpc-1.67.0.pre1 third_party/upb/upb/base/internal/endian.h
grpc-1.66.0 third_party/upb/upb/base/internal/endian.h
grpc-1.66.0.pre5 third_party/upb/upb/base/internal/endian.h
grpc-1.66.0.pre3 third_party/upb/upb/base/internal/endian.h
grpc-1.63.2 third_party/upb/upb/base/internal/endian.h
grpc-1.64.3 third_party/upb/upb/base/internal/endian.h
grpc-1.65.2 third_party/upb/upb/base/internal/endian.h
grpc-1.65.1 third_party/upb/upb/base/internal/endian.h
grpc-1.65.0 third_party/upb/upb/base/internal/endian.h
grpc-1.65.0.pre2 third_party/upb/upb/base/internal/endian.h
grpc-1.65.0.pre1 third_party/upb/upb/base/internal/endian.h
grpc-1.63.0 third_party/upb/upb/base/internal/endian.h