Sha256: aef0fc011dc31cc7eda2fca42badee76872feefd7007c8fd69df979607ae9327

Contents?: true

Size: 1.98 KB

Versions: 22

Compression:

Stored size: 1.98 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

#include "upb/reflection/internal/enum_reserved_range.h"

#include "upb/reflection/enum_def.h"
#include "upb/reflection/field_def.h"
#include "upb/reflection/internal/def_builder.h"

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

struct upb_EnumReservedRange {
  int32_t start;
  int32_t end;
};

upb_EnumReservedRange* _upb_EnumReservedRange_At(const upb_EnumReservedRange* r,
                                                 int i) {
  return (upb_EnumReservedRange*)&r[i];
}

int32_t upb_EnumReservedRange_Start(const upb_EnumReservedRange* r) {
  return r->start;
}
int32_t upb_EnumReservedRange_End(const upb_EnumReservedRange* r) {
  return r->end;
}

upb_EnumReservedRange* _upb_EnumReservedRanges_New(
    upb_DefBuilder* ctx, int n,
    const UPB_DESC(EnumDescriptorProto_EnumReservedRange) * const* protos,
    const upb_EnumDef* e) {
  upb_EnumReservedRange* r =
      _upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumReservedRange) * n);

  for (int i = 0; i < n; i++) {
    const int32_t start =
        UPB_DESC(EnumDescriptorProto_EnumReservedRange_start)(protos[i]);
    const int32_t end =
        UPB_DESC(EnumDescriptorProto_EnumReservedRange_end)(protos[i]);

    // A full validation would also check that each range is disjoint, and that
    // none of the fields overlap with the extension ranges, but we are just
    // sanity checking here.

    // Note: Not a typo! Unlike extension ranges and message reserved ranges,
    // the end value of an enum reserved range is *inclusive*!
    if (end < start) {
      _upb_DefBuilder_Errf(ctx, "Reserved range (%d, %d) is invalid, enum=%s\n",
                           (int)start, (int)end, upb_EnumDef_FullName(e));
    }

    r[i].start = start;
    r[i].end = end;
  }

  return r;
}

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
grpc-1.67.0 third_party/upb/upb/reflection/enum_reserved_range.c
grpc-1.67.0.pre1 third_party/upb/upb/reflection/enum_reserved_range.c
grpc-1.66.0 third_party/upb/upb/reflection/enum_reserved_range.c
grpc-1.66.0.pre5 third_party/upb/upb/reflection/enum_reserved_range.c
grpc-1.66.0.pre3 third_party/upb/upb/reflection/enum_reserved_range.c
grpc-1.60.2 third_party/upb/upb/reflection/enum_reserved_range.c
grpc-1.61.3 third_party/upb/upb/reflection/enum_reserved_range.c
grpc-1.62.3 third_party/upb/upb/reflection/enum_reserved_range.c
grpc-1.63.2 third_party/upb/upb/reflection/enum_reserved_range.c
grpc-1.64.3 third_party/upb/upb/reflection/enum_reserved_range.c
grpc-1.65.2 third_party/upb/upb/reflection/enum_reserved_range.c
grpc-1.65.1 third_party/upb/upb/reflection/enum_reserved_range.c
grpc-1.65.0 third_party/upb/upb/reflection/enum_reserved_range.c
grpc-1.65.0.pre2 third_party/upb/upb/reflection/enum_reserved_range.c
grpc-1.65.0.pre1 third_party/upb/upb/reflection/enum_reserved_range.c
grpc-1.63.0 third_party/upb/upb/reflection/enum_reserved_range.c
grpc-1.62.0 third_party/upb/upb/reflection/enum_reserved_range.c
grpc-1.62.0.pre1 third_party/upb/upb/reflection/enum_reserved_range.c
grpc-1.61.0 third_party/upb/upb/reflection/enum_reserved_range.c
grpc-1.61.0.pre2 third_party/upb/upb/reflection/enum_reserved_range.c