Compare commits
9 Commits
e080dd9c0c
...
d8329b68e4
Author | SHA1 | Date |
---|---|---|
Protobuf Team Bot | d8329b68e4 | |
Protobuf Team Bot | 6afb130dca | |
Eric Salo | d923896299 | |
Protobuf Team Bot | 4d3a98c27e | |
Eric Salo | 65821a67d6 | |
Éamonn McManus | 98d5bdd111 | |
Protobuf Team Bot | 5632d8e616 | |
Sandy Zhang | 94cf1e9446 | |
Protobuf Team Bot | 12af9ade1d |
|
@ -18,7 +18,7 @@ jobs:
|
|||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
branch: [main, 22.x, 23.x, 24.x, 25.x, 26.x]
|
||||
branch: [main, 25.x, 27.x]
|
||||
os: [{ name: Linux, value: ubuntu-latest}]
|
||||
|
||||
name: Test staleness ${{ matrix.os.name }} ${{ github.head_ref && 'PR' || matrix.branch }}
|
||||
|
|
15
WORKSPACE
15
WORKSPACE
|
@ -226,3 +226,18 @@ crates_repository(
|
|||
|
||||
load("@crate_index//:defs.bzl", "crate_repositories")
|
||||
crate_repositories()
|
||||
|
||||
# For testing runtime against old gencode from a previous major version.
|
||||
http_archive(
|
||||
name = "com_google_protobuf_v25.0",
|
||||
strip_prefix = "protobuf-25.0",
|
||||
url = "https://github.com/protocolbuffers/protobuf/releases/download/v25.0/protobuf-25.0.tar.gz",
|
||||
)
|
||||
|
||||
# Needed as a dependency of @com_google_protobuf_v25.x, which was before
|
||||
# utf8_range was merged in.
|
||||
http_archive(
|
||||
name = "utf8_range",
|
||||
strip_prefix = "utf8_range-d863bc33e15cba6d873c878dcca9e6fe52b2f8cb",
|
||||
url = "https://github.com/protocolbuffers/utf8_range/archive/d863bc33e15cba6d873c878dcca9e6fe52b2f8cb.zip",
|
||||
)
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
# Simple build tests for compatibility of gencode from previous major versions
|
||||
# with the current runtime.
|
||||
#
|
||||
# To add more test cases in Java, use java_runtime_conformance as below, and add
|
||||
# the corresponding http_archive in the WORKSPACE file for the version.
|
||||
|
||||
load("//compatibility:runtime_conformance.bzl", "java_runtime_conformance")
|
||||
|
||||
# main gencode builds with main runtime as a proof of concept.
|
||||
java_runtime_conformance(
|
||||
name = "java_conformance_main",
|
||||
gencode_version = "main",
|
||||
)
|
||||
|
||||
# Generates a build_test named "conformance_v3.25.0"
|
||||
java_runtime_conformance(
|
||||
name = "java_conformance_v3.25.0",
|
||||
gencode_version = "3.25.0",
|
||||
tags = ["manual"],
|
||||
)
|
|
@ -0,0 +1,53 @@
|
|||
"""Provides a rule to generate a conformance test for a given version of the gencode."""
|
||||
|
||||
load("@bazel_skylib//rules:build_test.bzl", "build_test")
|
||||
|
||||
def java_runtime_conformance(name, gencode_version, tags = []):
|
||||
"""Generates a conformance test for the given version of the runtime.
|
||||
|
||||
For example, runtime_conformance("3.19.4") will generate a build test named "conformance_v3.19.4"
|
||||
that will fail if the runtime at that version fails to compile the unittest proto.
|
||||
|
||||
Args:
|
||||
name: The name of the test.
|
||||
gencode_version: The version of the runtime to test.
|
||||
tags: Any tags to apply to the generated test.
|
||||
"""
|
||||
|
||||
if gencode_version == "main":
|
||||
protoc = "//:protoc"
|
||||
else:
|
||||
minor = gencode_version[gencode_version.find(".") + 1:]
|
||||
protoc = Label("@com_google_protobuf_v%s//:protoc" % minor)
|
||||
|
||||
gencode = [
|
||||
"v%s/protobuf_unittest/UnittestProto.java" % gencode_version,
|
||||
"v%s/com/google/protobuf/test/UnittestImport.java" % gencode_version,
|
||||
"v%s/com/google/protobuf/test/UnittestImportPublic.java" % gencode_version,
|
||||
]
|
||||
native.genrule(
|
||||
name = "unittest_proto_gencode_v" + gencode_version,
|
||||
srcs = [
|
||||
"//src/google/protobuf:unittest_proto_srcs",
|
||||
],
|
||||
outs = gencode,
|
||||
cmd = "$(location %s) " % protoc +
|
||||
"$(locations //src/google/protobuf:unittest_proto_srcs) " +
|
||||
" -Isrc/ --java_out=$(@D)/v%s" % gencode_version,
|
||||
tools = [protoc],
|
||||
)
|
||||
|
||||
conformance_name = "conformance_v" + gencode_version
|
||||
conformance_lib_name = conformance_name + "_lib"
|
||||
native.java_library(
|
||||
name = conformance_lib_name,
|
||||
srcs = gencode,
|
||||
deps = ["//java/core"],
|
||||
tags = tags,
|
||||
)
|
||||
|
||||
build_test(
|
||||
name = name,
|
||||
targets = [":" + conformance_lib_name],
|
||||
tags = tags,
|
||||
)
|
|
@ -6158,7 +6158,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
|
|||
return NULL;
|
||||
}
|
||||
UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)
|
||||
(dst, mini_table, field,
|
||||
(dst, field,
|
||||
UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(dst_sub_message,
|
||||
is_empty));
|
||||
}
|
||||
|
|
|
@ -413,113 +413,6 @@ void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt,
|
|||
#ifndef UPB_MESSAGE_ACCESSORS_H_
|
||||
#define UPB_MESSAGE_ACCESSORS_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#ifndef UPB_BASE_DESCRIPTOR_CONSTANTS_H_
|
||||
#define UPB_BASE_DESCRIPTOR_CONSTANTS_H_
|
||||
|
||||
// Must be last.
|
||||
|
||||
// The types a field can have. Note that this list is not identical to the
|
||||
// types defined in descriptor.proto, which gives INT32 and SINT32 separate
|
||||
// types (we distinguish the two with the "integer encoding" enum below).
|
||||
// This enum is an internal convenience only and has no meaning outside of upb.
|
||||
typedef enum {
|
||||
kUpb_CType_Bool = 1,
|
||||
kUpb_CType_Float = 2,
|
||||
kUpb_CType_Int32 = 3,
|
||||
kUpb_CType_UInt32 = 4,
|
||||
kUpb_CType_Enum = 5, // Enum values are int32. TODO: rename
|
||||
kUpb_CType_Message = 6,
|
||||
kUpb_CType_Double = 7,
|
||||
kUpb_CType_Int64 = 8,
|
||||
kUpb_CType_UInt64 = 9,
|
||||
kUpb_CType_String = 10,
|
||||
kUpb_CType_Bytes = 11
|
||||
} upb_CType;
|
||||
|
||||
// The repeated-ness of each field; this matches descriptor.proto.
|
||||
typedef enum {
|
||||
kUpb_Label_Optional = 1,
|
||||
kUpb_Label_Required = 2,
|
||||
kUpb_Label_Repeated = 3
|
||||
} upb_Label;
|
||||
|
||||
// Descriptor types, as defined in descriptor.proto.
|
||||
typedef enum {
|
||||
kUpb_FieldType_Double = 1,
|
||||
kUpb_FieldType_Float = 2,
|
||||
kUpb_FieldType_Int64 = 3,
|
||||
kUpb_FieldType_UInt64 = 4,
|
||||
kUpb_FieldType_Int32 = 5,
|
||||
kUpb_FieldType_Fixed64 = 6,
|
||||
kUpb_FieldType_Fixed32 = 7,
|
||||
kUpb_FieldType_Bool = 8,
|
||||
kUpb_FieldType_String = 9,
|
||||
kUpb_FieldType_Group = 10,
|
||||
kUpb_FieldType_Message = 11,
|
||||
kUpb_FieldType_Bytes = 12,
|
||||
kUpb_FieldType_UInt32 = 13,
|
||||
kUpb_FieldType_Enum = 14,
|
||||
kUpb_FieldType_SFixed32 = 15,
|
||||
kUpb_FieldType_SFixed64 = 16,
|
||||
kUpb_FieldType_SInt32 = 17,
|
||||
kUpb_FieldType_SInt64 = 18,
|
||||
} upb_FieldType;
|
||||
|
||||
#define kUpb_FieldType_SizeOf 19
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Convert from upb_FieldType to upb_CType
|
||||
UPB_INLINE upb_CType upb_FieldType_CType(upb_FieldType field_type) {
|
||||
static const upb_CType c_type[] = {
|
||||
kUpb_CType_Double, // kUpb_FieldType_Double
|
||||
kUpb_CType_Float, // kUpb_FieldType_Float
|
||||
kUpb_CType_Int64, // kUpb_FieldType_Int64
|
||||
kUpb_CType_UInt64, // kUpb_FieldType_UInt64
|
||||
kUpb_CType_Int32, // kUpb_FieldType_Int32
|
||||
kUpb_CType_UInt64, // kUpb_FieldType_Fixed64
|
||||
kUpb_CType_UInt32, // kUpb_FieldType_Fixed32
|
||||
kUpb_CType_Bool, // kUpb_FieldType_Bool
|
||||
kUpb_CType_String, // kUpb_FieldType_String
|
||||
kUpb_CType_Message, // kUpb_FieldType_Group
|
||||
kUpb_CType_Message, // kUpb_FieldType_Message
|
||||
kUpb_CType_Bytes, // kUpb_FieldType_Bytes
|
||||
kUpb_CType_UInt32, // kUpb_FieldType_UInt32
|
||||
kUpb_CType_Enum, // kUpb_FieldType_Enum
|
||||
kUpb_CType_Int32, // kUpb_FieldType_SFixed32
|
||||
kUpb_CType_Int64, // kUpb_FieldType_SFixed64
|
||||
kUpb_CType_Int32, // kUpb_FieldType_SInt32
|
||||
kUpb_CType_Int64, // kUpb_FieldType_SInt64
|
||||
};
|
||||
|
||||
// -1 here because the enum is one-based but the table is zero-based.
|
||||
return c_type[field_type - 1];
|
||||
}
|
||||
|
||||
UPB_INLINE bool upb_FieldType_IsPackable(upb_FieldType field_type) {
|
||||
// clang-format off
|
||||
const unsigned kUnpackableTypes =
|
||||
(1 << kUpb_FieldType_String) |
|
||||
(1 << kUpb_FieldType_Bytes) |
|
||||
(1 << kUpb_FieldType_Message) |
|
||||
(1 << kUpb_FieldType_Group);
|
||||
// clang-format on
|
||||
return (1 << field_type) & ~kUnpackableTypes;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* UPB_BASE_DESCRIPTOR_CONSTANTS_H_ */
|
||||
#ifndef UPB_BASE_STRING_VIEW_H_
|
||||
#define UPB_BASE_STRING_VIEW_H_
|
||||
|
||||
|
@ -827,6 +720,109 @@ void upb_Arena_SetTraceHandler(void (*initArenaTraceHandler)(const upb_Arena*,
|
|||
#include <stddef.h>
|
||||
|
||||
|
||||
#ifndef UPB_BASE_DESCRIPTOR_CONSTANTS_H_
|
||||
#define UPB_BASE_DESCRIPTOR_CONSTANTS_H_
|
||||
|
||||
// Must be last.
|
||||
|
||||
// The types a field can have. Note that this list is not identical to the
|
||||
// types defined in descriptor.proto, which gives INT32 and SINT32 separate
|
||||
// types (we distinguish the two with the "integer encoding" enum below).
|
||||
// This enum is an internal convenience only and has no meaning outside of upb.
|
||||
typedef enum {
|
||||
kUpb_CType_Bool = 1,
|
||||
kUpb_CType_Float = 2,
|
||||
kUpb_CType_Int32 = 3,
|
||||
kUpb_CType_UInt32 = 4,
|
||||
kUpb_CType_Enum = 5, // Enum values are int32. TODO: rename
|
||||
kUpb_CType_Message = 6,
|
||||
kUpb_CType_Double = 7,
|
||||
kUpb_CType_Int64 = 8,
|
||||
kUpb_CType_UInt64 = 9,
|
||||
kUpb_CType_String = 10,
|
||||
kUpb_CType_Bytes = 11
|
||||
} upb_CType;
|
||||
|
||||
// The repeated-ness of each field; this matches descriptor.proto.
|
||||
typedef enum {
|
||||
kUpb_Label_Optional = 1,
|
||||
kUpb_Label_Required = 2,
|
||||
kUpb_Label_Repeated = 3
|
||||
} upb_Label;
|
||||
|
||||
// Descriptor types, as defined in descriptor.proto.
|
||||
typedef enum {
|
||||
kUpb_FieldType_Double = 1,
|
||||
kUpb_FieldType_Float = 2,
|
||||
kUpb_FieldType_Int64 = 3,
|
||||
kUpb_FieldType_UInt64 = 4,
|
||||
kUpb_FieldType_Int32 = 5,
|
||||
kUpb_FieldType_Fixed64 = 6,
|
||||
kUpb_FieldType_Fixed32 = 7,
|
||||
kUpb_FieldType_Bool = 8,
|
||||
kUpb_FieldType_String = 9,
|
||||
kUpb_FieldType_Group = 10,
|
||||
kUpb_FieldType_Message = 11,
|
||||
kUpb_FieldType_Bytes = 12,
|
||||
kUpb_FieldType_UInt32 = 13,
|
||||
kUpb_FieldType_Enum = 14,
|
||||
kUpb_FieldType_SFixed32 = 15,
|
||||
kUpb_FieldType_SFixed64 = 16,
|
||||
kUpb_FieldType_SInt32 = 17,
|
||||
kUpb_FieldType_SInt64 = 18,
|
||||
} upb_FieldType;
|
||||
|
||||
#define kUpb_FieldType_SizeOf 19
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Convert from upb_FieldType to upb_CType
|
||||
UPB_INLINE upb_CType upb_FieldType_CType(upb_FieldType field_type) {
|
||||
static const upb_CType c_type[] = {
|
||||
kUpb_CType_Double, // kUpb_FieldType_Double
|
||||
kUpb_CType_Float, // kUpb_FieldType_Float
|
||||
kUpb_CType_Int64, // kUpb_FieldType_Int64
|
||||
kUpb_CType_UInt64, // kUpb_FieldType_UInt64
|
||||
kUpb_CType_Int32, // kUpb_FieldType_Int32
|
||||
kUpb_CType_UInt64, // kUpb_FieldType_Fixed64
|
||||
kUpb_CType_UInt32, // kUpb_FieldType_Fixed32
|
||||
kUpb_CType_Bool, // kUpb_FieldType_Bool
|
||||
kUpb_CType_String, // kUpb_FieldType_String
|
||||
kUpb_CType_Message, // kUpb_FieldType_Group
|
||||
kUpb_CType_Message, // kUpb_FieldType_Message
|
||||
kUpb_CType_Bytes, // kUpb_FieldType_Bytes
|
||||
kUpb_CType_UInt32, // kUpb_FieldType_UInt32
|
||||
kUpb_CType_Enum, // kUpb_FieldType_Enum
|
||||
kUpb_CType_Int32, // kUpb_FieldType_SFixed32
|
||||
kUpb_CType_Int64, // kUpb_FieldType_SFixed64
|
||||
kUpb_CType_Int32, // kUpb_FieldType_SInt32
|
||||
kUpb_CType_Int64, // kUpb_FieldType_SInt64
|
||||
};
|
||||
|
||||
// -1 here because the enum is one-based but the table is zero-based.
|
||||
return c_type[field_type - 1];
|
||||
}
|
||||
|
||||
UPB_INLINE bool upb_FieldType_IsPackable(upb_FieldType field_type) {
|
||||
// clang-format off
|
||||
const unsigned kUnpackableTypes =
|
||||
(1 << kUpb_FieldType_String) |
|
||||
(1 << kUpb_FieldType_Bytes) |
|
||||
(1 << kUpb_FieldType_Message) |
|
||||
(1 << kUpb_FieldType_Group);
|
||||
// clang-format on
|
||||
return (1 << field_type) & ~kUnpackableTypes;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* UPB_BASE_DESCRIPTOR_CONSTANTS_H_ */
|
||||
|
||||
#ifndef UPB_MESSAGE_INTERNAL_ARRAY_H_
|
||||
#define UPB_MESSAGE_INTERNAL_ARRAY_H_
|
||||
|
||||
|
@ -1882,6 +1878,11 @@ UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage(
|
|||
e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg) = m;
|
||||
}
|
||||
|
||||
UPB_INLINE upb_FieldRep UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(
|
||||
const struct upb_MiniTableExtension* e) {
|
||||
return UPB_PRIVATE(_upb_MiniTableField_GetRep)(&e->UPB_PRIVATE(field));
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
@ -2796,7 +2797,6 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(
|
|||
// const upb_MiniTableField* field,
|
||||
// bool value, upb_Arena* a) {
|
||||
// UPB_ASSUME(field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Bool);
|
||||
// UPB_ASSUME(upb_MiniTableField_IsScalar(field));
|
||||
// UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) ==
|
||||
// kUpb_FieldRep_1Byte);
|
||||
// upb_Message_SetField(msg, field, &value, a);
|
||||
|
@ -2927,8 +2927,8 @@ UPB_API_INLINE bool upb_Message_GetBool(const struct upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
bool default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Bool);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
|
||||
upb_MessageValue def;
|
||||
def.bool_val = default_val;
|
||||
return upb_Message_GetField(msg, f, def).bool_val;
|
||||
|
@ -2938,8 +2938,8 @@ UPB_API_INLINE double upb_Message_GetDouble(const struct upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
double default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Double);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
|
||||
upb_MessageValue def;
|
||||
def.double_val = default_val;
|
||||
|
@ -2950,8 +2950,8 @@ UPB_API_INLINE float upb_Message_GetFloat(const struct upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
float default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Float);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
|
||||
upb_MessageValue def;
|
||||
def.float_val = default_val;
|
||||
|
@ -2963,8 +2963,8 @@ UPB_API_INLINE int32_t upb_Message_GetInt32(const struct upb_Message* msg,
|
|||
int32_t default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int32 ||
|
||||
upb_MiniTableField_CType(f) == kUpb_CType_Enum);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
|
||||
upb_MessageValue def;
|
||||
def.int32_val = default_val;
|
||||
|
@ -2975,8 +2975,8 @@ UPB_API_INLINE int64_t upb_Message_GetInt64(const struct upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
int64_t default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int64);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
|
||||
upb_MessageValue def;
|
||||
def.int64_val = default_val;
|
||||
|
@ -3005,6 +3005,37 @@ UPB_API_INLINE const struct upb_Map* upb_Message_GetMap(
|
|||
return ret;
|
||||
}
|
||||
|
||||
UPB_API_INLINE uintptr_t upb_Message_GetTaggedMessagePtr(
|
||||
const struct upb_Message* msg, const upb_MiniTableField* f,
|
||||
struct upb_Message* default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
|
||||
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
uintptr_t tagged;
|
||||
_upb_Message_GetNonExtensionField(msg, f, &default_val, &tagged);
|
||||
return tagged;
|
||||
}
|
||||
|
||||
// For internal use only; users cannot set tagged messages because only the
|
||||
// parser and the message copier are allowed to directly create an empty
|
||||
// message.
|
||||
UPB_INLINE void UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)(
|
||||
struct upb_Message* msg, const upb_MiniTableField* f,
|
||||
uintptr_t sub_message) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
|
||||
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_Message_SetBaseField(msg, f, &sub_message);
|
||||
}
|
||||
|
||||
UPB_API_INLINE const struct upb_Message* upb_Message_GetMessage(
|
||||
const struct upb_Message* msg, const upb_MiniTableField* f) {
|
||||
uintptr_t tagged = upb_Message_GetTaggedMessagePtr(msg, f, NULL);
|
||||
return upb_TaggedMessagePtr_GetNonEmptyMessage(tagged);
|
||||
}
|
||||
|
||||
UPB_API_INLINE upb_Array* upb_Message_GetMutableArray(
|
||||
struct upb_Message* msg, const upb_MiniTableField* f) {
|
||||
UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(f);
|
||||
|
@ -3016,6 +3047,11 @@ UPB_API_INLINE struct upb_Map* upb_Message_GetMutableMap(
|
|||
return (struct upb_Map*)upb_Message_GetMap(msg, f);
|
||||
}
|
||||
|
||||
UPB_API_INLINE struct upb_Message* upb_Message_GetMutableMessage(
|
||||
struct upb_Message* msg, const upb_MiniTableField* f) {
|
||||
return (struct upb_Message*)upb_Message_GetMessage(msg, f);
|
||||
}
|
||||
|
||||
UPB_API_INLINE upb_Array* upb_Message_GetOrCreateMutableArray(
|
||||
struct upb_Message* msg, const upb_MiniTableField* f, upb_Arena* arena) {
|
||||
UPB_ASSERT(arena);
|
||||
|
@ -3091,7 +3127,6 @@ upb_Message_GetString(const struct upb_Message* msg,
|
|||
upb_MiniTableField_CType(f) == kUpb_CType_Bytes);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
|
||||
kUpb_FieldRep_StringView);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
|
||||
upb_MessageValue def;
|
||||
def.str_val = default_val;
|
||||
|
@ -3102,8 +3137,8 @@ UPB_API_INLINE uint32_t upb_Message_GetUInt32(const struct upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
uint32_t default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt32);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
|
||||
upb_MessageValue def;
|
||||
def.uint32_val = default_val;
|
||||
|
@ -3114,23 +3149,89 @@ UPB_API_INLINE uint64_t upb_Message_GetUInt64(const struct upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
uint64_t default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt64);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
|
||||
upb_MessageValue def;
|
||||
def.uint64_val = default_val;
|
||||
return upb_Message_GetField(msg, f, def).uint64_val;
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetBool(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f, bool value,
|
||||
upb_Arena* a) {
|
||||
// BaseField Setters ///////////////////////////////////////////////////////////
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldBool(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
bool value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Bool);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.bool_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldDouble(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
double value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Double);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldFloat(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
float value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Float);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldInt32(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
int32_t value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int32 ||
|
||||
upb_MiniTableField_CType(f) == kUpb_CType_Enum);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldInt64(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
int64_t value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int64);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldString(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
upb_StringView value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_String ||
|
||||
upb_MiniTableField_CType(f) == kUpb_CType_Bytes);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
|
||||
kUpb_FieldRep_StringView);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldUInt32(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
uint32_t value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt32);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldUInt64(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
uint64_t value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt64);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetClosedEnum(
|
||||
|
@ -3138,55 +3239,142 @@ UPB_API_INLINE void upb_Message_SetClosedEnum(
|
|||
const upb_MiniTableField* f, int32_t value) {
|
||||
UPB_ASSERT(upb_MiniTableField_IsClosedEnum(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSERT(upb_MiniTableEnum_CheckValue(
|
||||
upb_MiniTable_GetSubEnumTable(msg_mini_table, f), value));
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
// Extension Setters ///////////////////////////////////////////////////////////
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionBool(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e, bool value,
|
||||
upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Bool);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_1Byte);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionDouble(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e, double value,
|
||||
upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Double);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_8Byte);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionFloat(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e, float value,
|
||||
upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Float);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_4Byte);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionInt32(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e, int32_t value,
|
||||
upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Int32 ||
|
||||
upb_MiniTableExtension_CType(e) == kUpb_CType_Enum);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_4Byte);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionInt64(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e, int64_t value,
|
||||
upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Int64);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_8Byte);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionString(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e,
|
||||
upb_StringView value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_String ||
|
||||
upb_MiniTableExtension_CType(e) == kUpb_CType_Bytes);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_StringView);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionUInt32(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e, uint32_t value,
|
||||
upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_UInt32);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_4Byte);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionUInt64(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e, uint64_t value,
|
||||
upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_UInt64);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_8Byte);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
// Universal Setters ///////////////////////////////////////////////////////////
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetBool(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f, bool value,
|
||||
upb_Arena* a) {
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionBool(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldBool(msg, f, value), true);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetDouble(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
double value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Double);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.double_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionDouble(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldDouble(msg, f, value), true);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetFloat(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
float value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Float);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.float_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionFloat(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldFloat(msg, f, value), true);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetInt32(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
int32_t value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int32 ||
|
||||
upb_MiniTableField_CType(f) == kUpb_CType_Enum);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.int32_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionInt32(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldInt32(msg, f, value), true);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetInt64(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
int64_t value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int64);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.int64_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionInt64(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldInt64(msg, f, value), true);
|
||||
}
|
||||
|
||||
// Sets the value of a message-typed field. The mini_tables of `msg` and
|
||||
// `sub_message` must have been linked for this to work correctly.
|
||||
UPB_API_INLINE void upb_Message_SetMessage(struct upb_Message* msg,
|
||||
const upb_MiniTable* m,
|
||||
const upb_MiniTableField* f,
|
||||
struct upb_Message* sub_message) {
|
||||
UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)
|
||||
(msg, f, UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(sub_message, false));
|
||||
}
|
||||
|
||||
// Sets the value of a `string` or `bytes` field. The bytes of the value are not
|
||||
|
@ -3196,36 +3384,28 @@ UPB_API_INLINE bool upb_Message_SetInt64(struct upb_Message* msg,
|
|||
UPB_API_INLINE bool upb_Message_SetString(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
upb_StringView value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_String ||
|
||||
upb_MiniTableField_CType(f) == kUpb_CType_Bytes);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
|
||||
kUpb_FieldRep_StringView);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.str_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionString(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldString(msg, f, value), true);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetUInt32(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
uint32_t value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt32);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.uint32_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionUInt32(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldUInt32(msg, f, value), true);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetUInt64(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
uint64_t value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt64);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.uint64_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionUInt64(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldUInt64(msg, f, value), true);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_Clear(struct upb_Message* msg,
|
||||
|
@ -3504,41 +3684,6 @@ UPB_API_INLINE upb_Message* upb_TaggedMessagePtr_GetNonEmptyMessage(
|
|||
|
||||
#endif /* UPB_MINI_TABLE_TAGGED_PTR_H_ */
|
||||
|
||||
#ifndef UPB_MINI_TABLE_SUB_H_
|
||||
#define UPB_MINI_TABLE_SUB_H_
|
||||
|
||||
|
||||
// Must be last.
|
||||
|
||||
typedef union upb_MiniTableSub upb_MiniTableSub;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Constructors
|
||||
|
||||
UPB_API_INLINE upb_MiniTableSub
|
||||
upb_MiniTableSub_FromEnum(const upb_MiniTableEnum* subenum);
|
||||
|
||||
UPB_API_INLINE upb_MiniTableSub
|
||||
upb_MiniTableSub_FromMessage(const upb_MiniTable* submsg);
|
||||
|
||||
// Getters
|
||||
|
||||
UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableSub_Enum(
|
||||
upb_MiniTableSub sub);
|
||||
|
||||
UPB_API_INLINE const upb_MiniTable* upb_MiniTableSub_Message(
|
||||
upb_MiniTableSub sub);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* UPB_MINI_TABLE_SUB_H_ */
|
||||
|
||||
// Must be last.
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -3581,6 +3726,10 @@ UPB_API_INLINE upb_MessageValue
|
|||
upb_Message_GetField(const upb_Message* msg, const upb_MiniTableField* f,
|
||||
upb_MessageValue default_val);
|
||||
|
||||
UPB_API_INLINE upb_TaggedMessagePtr upb_Message_GetTaggedMessagePtr(
|
||||
const upb_Message* msg, const upb_MiniTableField* field,
|
||||
upb_Message* default_val);
|
||||
|
||||
UPB_API_INLINE const upb_Array* upb_Message_GetArray(
|
||||
const upb_Message* msg, const upb_MiniTableField* f);
|
||||
|
||||
|
@ -3607,12 +3756,18 @@ UPB_API_INLINE int64_t upb_Message_GetInt64(const upb_Message* msg,
|
|||
UPB_API_INLINE const upb_Map* upb_Message_GetMap(const upb_Message* msg,
|
||||
const upb_MiniTableField* f);
|
||||
|
||||
UPB_API_INLINE const upb_Message* upb_Message_GetMessage(
|
||||
const upb_Message* msg, const upb_MiniTableField* f);
|
||||
|
||||
UPB_API_INLINE upb_Array* upb_Message_GetMutableArray(
|
||||
upb_Message* msg, const upb_MiniTableField* f);
|
||||
|
||||
UPB_API_INLINE upb_Map* upb_Message_GetMutableMap(upb_Message* msg,
|
||||
const upb_MiniTableField* f);
|
||||
|
||||
UPB_API_INLINE upb_Message* upb_Message_GetMutableMessage(
|
||||
upb_Message* msg, const upb_MiniTableField* f);
|
||||
|
||||
UPB_API_INLINE upb_Array* upb_Message_GetOrCreateMutableArray(
|
||||
upb_Message* msg, const upb_MiniTableField* f, upb_Arena* arena);
|
||||
|
||||
|
@ -3660,6 +3815,11 @@ UPB_API_INLINE bool upb_Message_SetInt64(upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
int64_t value, upb_Arena* a);
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetMessage(upb_Message* msg,
|
||||
const upb_MiniTable* m,
|
||||
const upb_MiniTableField* f,
|
||||
upb_Message* sub_message);
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetString(upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
upb_StringView value, upb_Arena* a);
|
||||
|
@ -3672,55 +3832,6 @@ UPB_API_INLINE bool upb_Message_SetUInt64(upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
uint64_t value, upb_Arena* a);
|
||||
|
||||
UPB_API_INLINE upb_TaggedMessagePtr upb_Message_GetTaggedMessagePtr(
|
||||
const upb_Message* msg, const upb_MiniTableField* field,
|
||||
upb_Message* default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Message);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) ==
|
||||
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(field));
|
||||
upb_TaggedMessagePtr tagged;
|
||||
_upb_Message_GetNonExtensionField(msg, field, &default_val, &tagged);
|
||||
return tagged;
|
||||
}
|
||||
|
||||
UPB_API_INLINE const upb_Message* upb_Message_GetMessage(
|
||||
const upb_Message* msg, const upb_MiniTableField* field) {
|
||||
upb_TaggedMessagePtr tagged =
|
||||
upb_Message_GetTaggedMessagePtr(msg, field, NULL);
|
||||
return upb_TaggedMessagePtr_GetNonEmptyMessage(tagged);
|
||||
}
|
||||
|
||||
UPB_API_INLINE upb_Message* upb_Message_GetMutableMessage(
|
||||
upb_Message* msg, const upb_MiniTableField* field) {
|
||||
return (upb_Message*)upb_Message_GetMessage(msg, field);
|
||||
}
|
||||
|
||||
// For internal use only; users cannot set tagged messages because only the
|
||||
// parser and the message copier are allowed to directly create an empty
|
||||
// message.
|
||||
UPB_INLINE void UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)(
|
||||
struct upb_Message* msg, const upb_MiniTable* mini_table,
|
||||
const upb_MiniTableField* f, upb_TaggedMessagePtr sub_message) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
|
||||
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_Message_SetBaseField(msg, f, &sub_message);
|
||||
}
|
||||
|
||||
// Sets the value of a message-typed field. The `mini_table` and `field`
|
||||
// parameters belong to `msg`, not `sub_message`. The mini_tables of `msg` and
|
||||
// `sub_message` must have been linked for this to work correctly.
|
||||
UPB_API_INLINE void upb_Message_SetMessage(upb_Message* msg,
|
||||
const upb_MiniTable* mini_table,
|
||||
const upb_MiniTableField* field,
|
||||
upb_Message* sub_message) {
|
||||
UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)
|
||||
(msg, mini_table, field,
|
||||
UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(sub_message, false));
|
||||
}
|
||||
|
||||
UPB_API_INLINE void* upb_Message_ResizeArrayUninitialized(
|
||||
upb_Message* msg, const upb_MiniTableField* f, size_t size,
|
||||
upb_Arena* arena);
|
||||
|
@ -3793,6 +3904,41 @@ UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val,
|
|||
#define UPB_MINI_TABLE_DECODE_H_
|
||||
|
||||
|
||||
#ifndef UPB_MINI_TABLE_SUB_H_
|
||||
#define UPB_MINI_TABLE_SUB_H_
|
||||
|
||||
|
||||
// Must be last.
|
||||
|
||||
typedef union upb_MiniTableSub upb_MiniTableSub;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Constructors
|
||||
|
||||
UPB_API_INLINE upb_MiniTableSub
|
||||
upb_MiniTableSub_FromEnum(const upb_MiniTableEnum* subenum);
|
||||
|
||||
UPB_API_INLINE upb_MiniTableSub
|
||||
upb_MiniTableSub_FromMessage(const upb_MiniTable* submsg);
|
||||
|
||||
// Getters
|
||||
|
||||
UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableSub_Enum(
|
||||
upb_MiniTableSub sub);
|
||||
|
||||
UPB_API_INLINE const upb_MiniTable* upb_MiniTableSub_Message(
|
||||
upb_MiniTableSub sub);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* UPB_MINI_TABLE_SUB_H_ */
|
||||
|
||||
// Export the newer headers, for legacy users. New users should include the
|
||||
// more specific headers directly.
|
||||
// IWYU pragma: begin_exports
|
||||
|
|
|
@ -5650,7 +5650,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
|
|||
return NULL;
|
||||
}
|
||||
UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)
|
||||
(dst, mini_table, field,
|
||||
(dst, field,
|
||||
UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(dst_sub_message,
|
||||
is_empty));
|
||||
}
|
||||
|
|
|
@ -415,113 +415,6 @@ void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt,
|
|||
#ifndef UPB_MESSAGE_ACCESSORS_H_
|
||||
#define UPB_MESSAGE_ACCESSORS_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#ifndef UPB_BASE_DESCRIPTOR_CONSTANTS_H_
|
||||
#define UPB_BASE_DESCRIPTOR_CONSTANTS_H_
|
||||
|
||||
// Must be last.
|
||||
|
||||
// The types a field can have. Note that this list is not identical to the
|
||||
// types defined in descriptor.proto, which gives INT32 and SINT32 separate
|
||||
// types (we distinguish the two with the "integer encoding" enum below).
|
||||
// This enum is an internal convenience only and has no meaning outside of upb.
|
||||
typedef enum {
|
||||
kUpb_CType_Bool = 1,
|
||||
kUpb_CType_Float = 2,
|
||||
kUpb_CType_Int32 = 3,
|
||||
kUpb_CType_UInt32 = 4,
|
||||
kUpb_CType_Enum = 5, // Enum values are int32. TODO: rename
|
||||
kUpb_CType_Message = 6,
|
||||
kUpb_CType_Double = 7,
|
||||
kUpb_CType_Int64 = 8,
|
||||
kUpb_CType_UInt64 = 9,
|
||||
kUpb_CType_String = 10,
|
||||
kUpb_CType_Bytes = 11
|
||||
} upb_CType;
|
||||
|
||||
// The repeated-ness of each field; this matches descriptor.proto.
|
||||
typedef enum {
|
||||
kUpb_Label_Optional = 1,
|
||||
kUpb_Label_Required = 2,
|
||||
kUpb_Label_Repeated = 3
|
||||
} upb_Label;
|
||||
|
||||
// Descriptor types, as defined in descriptor.proto.
|
||||
typedef enum {
|
||||
kUpb_FieldType_Double = 1,
|
||||
kUpb_FieldType_Float = 2,
|
||||
kUpb_FieldType_Int64 = 3,
|
||||
kUpb_FieldType_UInt64 = 4,
|
||||
kUpb_FieldType_Int32 = 5,
|
||||
kUpb_FieldType_Fixed64 = 6,
|
||||
kUpb_FieldType_Fixed32 = 7,
|
||||
kUpb_FieldType_Bool = 8,
|
||||
kUpb_FieldType_String = 9,
|
||||
kUpb_FieldType_Group = 10,
|
||||
kUpb_FieldType_Message = 11,
|
||||
kUpb_FieldType_Bytes = 12,
|
||||
kUpb_FieldType_UInt32 = 13,
|
||||
kUpb_FieldType_Enum = 14,
|
||||
kUpb_FieldType_SFixed32 = 15,
|
||||
kUpb_FieldType_SFixed64 = 16,
|
||||
kUpb_FieldType_SInt32 = 17,
|
||||
kUpb_FieldType_SInt64 = 18,
|
||||
} upb_FieldType;
|
||||
|
||||
#define kUpb_FieldType_SizeOf 19
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Convert from upb_FieldType to upb_CType
|
||||
UPB_INLINE upb_CType upb_FieldType_CType(upb_FieldType field_type) {
|
||||
static const upb_CType c_type[] = {
|
||||
kUpb_CType_Double, // kUpb_FieldType_Double
|
||||
kUpb_CType_Float, // kUpb_FieldType_Float
|
||||
kUpb_CType_Int64, // kUpb_FieldType_Int64
|
||||
kUpb_CType_UInt64, // kUpb_FieldType_UInt64
|
||||
kUpb_CType_Int32, // kUpb_FieldType_Int32
|
||||
kUpb_CType_UInt64, // kUpb_FieldType_Fixed64
|
||||
kUpb_CType_UInt32, // kUpb_FieldType_Fixed32
|
||||
kUpb_CType_Bool, // kUpb_FieldType_Bool
|
||||
kUpb_CType_String, // kUpb_FieldType_String
|
||||
kUpb_CType_Message, // kUpb_FieldType_Group
|
||||
kUpb_CType_Message, // kUpb_FieldType_Message
|
||||
kUpb_CType_Bytes, // kUpb_FieldType_Bytes
|
||||
kUpb_CType_UInt32, // kUpb_FieldType_UInt32
|
||||
kUpb_CType_Enum, // kUpb_FieldType_Enum
|
||||
kUpb_CType_Int32, // kUpb_FieldType_SFixed32
|
||||
kUpb_CType_Int64, // kUpb_FieldType_SFixed64
|
||||
kUpb_CType_Int32, // kUpb_FieldType_SInt32
|
||||
kUpb_CType_Int64, // kUpb_FieldType_SInt64
|
||||
};
|
||||
|
||||
// -1 here because the enum is one-based but the table is zero-based.
|
||||
return c_type[field_type - 1];
|
||||
}
|
||||
|
||||
UPB_INLINE bool upb_FieldType_IsPackable(upb_FieldType field_type) {
|
||||
// clang-format off
|
||||
const unsigned kUnpackableTypes =
|
||||
(1 << kUpb_FieldType_String) |
|
||||
(1 << kUpb_FieldType_Bytes) |
|
||||
(1 << kUpb_FieldType_Message) |
|
||||
(1 << kUpb_FieldType_Group);
|
||||
// clang-format on
|
||||
return (1 << field_type) & ~kUnpackableTypes;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* UPB_BASE_DESCRIPTOR_CONSTANTS_H_ */
|
||||
#ifndef UPB_BASE_STRING_VIEW_H_
|
||||
#define UPB_BASE_STRING_VIEW_H_
|
||||
|
||||
|
@ -829,6 +722,109 @@ void upb_Arena_SetTraceHandler(void (*initArenaTraceHandler)(const upb_Arena*,
|
|||
#include <stddef.h>
|
||||
|
||||
|
||||
#ifndef UPB_BASE_DESCRIPTOR_CONSTANTS_H_
|
||||
#define UPB_BASE_DESCRIPTOR_CONSTANTS_H_
|
||||
|
||||
// Must be last.
|
||||
|
||||
// The types a field can have. Note that this list is not identical to the
|
||||
// types defined in descriptor.proto, which gives INT32 and SINT32 separate
|
||||
// types (we distinguish the two with the "integer encoding" enum below).
|
||||
// This enum is an internal convenience only and has no meaning outside of upb.
|
||||
typedef enum {
|
||||
kUpb_CType_Bool = 1,
|
||||
kUpb_CType_Float = 2,
|
||||
kUpb_CType_Int32 = 3,
|
||||
kUpb_CType_UInt32 = 4,
|
||||
kUpb_CType_Enum = 5, // Enum values are int32. TODO: rename
|
||||
kUpb_CType_Message = 6,
|
||||
kUpb_CType_Double = 7,
|
||||
kUpb_CType_Int64 = 8,
|
||||
kUpb_CType_UInt64 = 9,
|
||||
kUpb_CType_String = 10,
|
||||
kUpb_CType_Bytes = 11
|
||||
} upb_CType;
|
||||
|
||||
// The repeated-ness of each field; this matches descriptor.proto.
|
||||
typedef enum {
|
||||
kUpb_Label_Optional = 1,
|
||||
kUpb_Label_Required = 2,
|
||||
kUpb_Label_Repeated = 3
|
||||
} upb_Label;
|
||||
|
||||
// Descriptor types, as defined in descriptor.proto.
|
||||
typedef enum {
|
||||
kUpb_FieldType_Double = 1,
|
||||
kUpb_FieldType_Float = 2,
|
||||
kUpb_FieldType_Int64 = 3,
|
||||
kUpb_FieldType_UInt64 = 4,
|
||||
kUpb_FieldType_Int32 = 5,
|
||||
kUpb_FieldType_Fixed64 = 6,
|
||||
kUpb_FieldType_Fixed32 = 7,
|
||||
kUpb_FieldType_Bool = 8,
|
||||
kUpb_FieldType_String = 9,
|
||||
kUpb_FieldType_Group = 10,
|
||||
kUpb_FieldType_Message = 11,
|
||||
kUpb_FieldType_Bytes = 12,
|
||||
kUpb_FieldType_UInt32 = 13,
|
||||
kUpb_FieldType_Enum = 14,
|
||||
kUpb_FieldType_SFixed32 = 15,
|
||||
kUpb_FieldType_SFixed64 = 16,
|
||||
kUpb_FieldType_SInt32 = 17,
|
||||
kUpb_FieldType_SInt64 = 18,
|
||||
} upb_FieldType;
|
||||
|
||||
#define kUpb_FieldType_SizeOf 19
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Convert from upb_FieldType to upb_CType
|
||||
UPB_INLINE upb_CType upb_FieldType_CType(upb_FieldType field_type) {
|
||||
static const upb_CType c_type[] = {
|
||||
kUpb_CType_Double, // kUpb_FieldType_Double
|
||||
kUpb_CType_Float, // kUpb_FieldType_Float
|
||||
kUpb_CType_Int64, // kUpb_FieldType_Int64
|
||||
kUpb_CType_UInt64, // kUpb_FieldType_UInt64
|
||||
kUpb_CType_Int32, // kUpb_FieldType_Int32
|
||||
kUpb_CType_UInt64, // kUpb_FieldType_Fixed64
|
||||
kUpb_CType_UInt32, // kUpb_FieldType_Fixed32
|
||||
kUpb_CType_Bool, // kUpb_FieldType_Bool
|
||||
kUpb_CType_String, // kUpb_FieldType_String
|
||||
kUpb_CType_Message, // kUpb_FieldType_Group
|
||||
kUpb_CType_Message, // kUpb_FieldType_Message
|
||||
kUpb_CType_Bytes, // kUpb_FieldType_Bytes
|
||||
kUpb_CType_UInt32, // kUpb_FieldType_UInt32
|
||||
kUpb_CType_Enum, // kUpb_FieldType_Enum
|
||||
kUpb_CType_Int32, // kUpb_FieldType_SFixed32
|
||||
kUpb_CType_Int64, // kUpb_FieldType_SFixed64
|
||||
kUpb_CType_Int32, // kUpb_FieldType_SInt32
|
||||
kUpb_CType_Int64, // kUpb_FieldType_SInt64
|
||||
};
|
||||
|
||||
// -1 here because the enum is one-based but the table is zero-based.
|
||||
return c_type[field_type - 1];
|
||||
}
|
||||
|
||||
UPB_INLINE bool upb_FieldType_IsPackable(upb_FieldType field_type) {
|
||||
// clang-format off
|
||||
const unsigned kUnpackableTypes =
|
||||
(1 << kUpb_FieldType_String) |
|
||||
(1 << kUpb_FieldType_Bytes) |
|
||||
(1 << kUpb_FieldType_Message) |
|
||||
(1 << kUpb_FieldType_Group);
|
||||
// clang-format on
|
||||
return (1 << field_type) & ~kUnpackableTypes;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* UPB_BASE_DESCRIPTOR_CONSTANTS_H_ */
|
||||
|
||||
#ifndef UPB_MESSAGE_INTERNAL_ARRAY_H_
|
||||
#define UPB_MESSAGE_INTERNAL_ARRAY_H_
|
||||
|
||||
|
@ -1884,6 +1880,11 @@ UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage(
|
|||
e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg) = m;
|
||||
}
|
||||
|
||||
UPB_INLINE upb_FieldRep UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(
|
||||
const struct upb_MiniTableExtension* e) {
|
||||
return UPB_PRIVATE(_upb_MiniTableField_GetRep)(&e->UPB_PRIVATE(field));
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
@ -2798,7 +2799,6 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(
|
|||
// const upb_MiniTableField* field,
|
||||
// bool value, upb_Arena* a) {
|
||||
// UPB_ASSUME(field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Bool);
|
||||
// UPB_ASSUME(upb_MiniTableField_IsScalar(field));
|
||||
// UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) ==
|
||||
// kUpb_FieldRep_1Byte);
|
||||
// upb_Message_SetField(msg, field, &value, a);
|
||||
|
@ -2929,8 +2929,8 @@ UPB_API_INLINE bool upb_Message_GetBool(const struct upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
bool default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Bool);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
|
||||
upb_MessageValue def;
|
||||
def.bool_val = default_val;
|
||||
return upb_Message_GetField(msg, f, def).bool_val;
|
||||
|
@ -2940,8 +2940,8 @@ UPB_API_INLINE double upb_Message_GetDouble(const struct upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
double default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Double);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
|
||||
upb_MessageValue def;
|
||||
def.double_val = default_val;
|
||||
|
@ -2952,8 +2952,8 @@ UPB_API_INLINE float upb_Message_GetFloat(const struct upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
float default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Float);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
|
||||
upb_MessageValue def;
|
||||
def.float_val = default_val;
|
||||
|
@ -2965,8 +2965,8 @@ UPB_API_INLINE int32_t upb_Message_GetInt32(const struct upb_Message* msg,
|
|||
int32_t default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int32 ||
|
||||
upb_MiniTableField_CType(f) == kUpb_CType_Enum);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
|
||||
upb_MessageValue def;
|
||||
def.int32_val = default_val;
|
||||
|
@ -2977,8 +2977,8 @@ UPB_API_INLINE int64_t upb_Message_GetInt64(const struct upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
int64_t default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int64);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
|
||||
upb_MessageValue def;
|
||||
def.int64_val = default_val;
|
||||
|
@ -3007,6 +3007,37 @@ UPB_API_INLINE const struct upb_Map* upb_Message_GetMap(
|
|||
return ret;
|
||||
}
|
||||
|
||||
UPB_API_INLINE uintptr_t upb_Message_GetTaggedMessagePtr(
|
||||
const struct upb_Message* msg, const upb_MiniTableField* f,
|
||||
struct upb_Message* default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
|
||||
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
uintptr_t tagged;
|
||||
_upb_Message_GetNonExtensionField(msg, f, &default_val, &tagged);
|
||||
return tagged;
|
||||
}
|
||||
|
||||
// For internal use only; users cannot set tagged messages because only the
|
||||
// parser and the message copier are allowed to directly create an empty
|
||||
// message.
|
||||
UPB_INLINE void UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)(
|
||||
struct upb_Message* msg, const upb_MiniTableField* f,
|
||||
uintptr_t sub_message) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
|
||||
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_Message_SetBaseField(msg, f, &sub_message);
|
||||
}
|
||||
|
||||
UPB_API_INLINE const struct upb_Message* upb_Message_GetMessage(
|
||||
const struct upb_Message* msg, const upb_MiniTableField* f) {
|
||||
uintptr_t tagged = upb_Message_GetTaggedMessagePtr(msg, f, NULL);
|
||||
return upb_TaggedMessagePtr_GetNonEmptyMessage(tagged);
|
||||
}
|
||||
|
||||
UPB_API_INLINE upb_Array* upb_Message_GetMutableArray(
|
||||
struct upb_Message* msg, const upb_MiniTableField* f) {
|
||||
UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(f);
|
||||
|
@ -3018,6 +3049,11 @@ UPB_API_INLINE struct upb_Map* upb_Message_GetMutableMap(
|
|||
return (struct upb_Map*)upb_Message_GetMap(msg, f);
|
||||
}
|
||||
|
||||
UPB_API_INLINE struct upb_Message* upb_Message_GetMutableMessage(
|
||||
struct upb_Message* msg, const upb_MiniTableField* f) {
|
||||
return (struct upb_Message*)upb_Message_GetMessage(msg, f);
|
||||
}
|
||||
|
||||
UPB_API_INLINE upb_Array* upb_Message_GetOrCreateMutableArray(
|
||||
struct upb_Message* msg, const upb_MiniTableField* f, upb_Arena* arena) {
|
||||
UPB_ASSERT(arena);
|
||||
|
@ -3093,7 +3129,6 @@ upb_Message_GetString(const struct upb_Message* msg,
|
|||
upb_MiniTableField_CType(f) == kUpb_CType_Bytes);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
|
||||
kUpb_FieldRep_StringView);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
|
||||
upb_MessageValue def;
|
||||
def.str_val = default_val;
|
||||
|
@ -3104,8 +3139,8 @@ UPB_API_INLINE uint32_t upb_Message_GetUInt32(const struct upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
uint32_t default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt32);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
|
||||
upb_MessageValue def;
|
||||
def.uint32_val = default_val;
|
||||
|
@ -3116,23 +3151,89 @@ UPB_API_INLINE uint64_t upb_Message_GetUInt64(const struct upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
uint64_t default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt64);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
|
||||
upb_MessageValue def;
|
||||
def.uint64_val = default_val;
|
||||
return upb_Message_GetField(msg, f, def).uint64_val;
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetBool(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f, bool value,
|
||||
upb_Arena* a) {
|
||||
// BaseField Setters ///////////////////////////////////////////////////////////
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldBool(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
bool value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Bool);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.bool_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldDouble(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
double value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Double);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldFloat(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
float value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Float);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldInt32(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
int32_t value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int32 ||
|
||||
upb_MiniTableField_CType(f) == kUpb_CType_Enum);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldInt64(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
int64_t value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int64);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldString(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
upb_StringView value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_String ||
|
||||
upb_MiniTableField_CType(f) == kUpb_CType_Bytes);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
|
||||
kUpb_FieldRep_StringView);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldUInt32(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
uint32_t value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt32);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldUInt64(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
uint64_t value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt64);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetClosedEnum(
|
||||
|
@ -3140,55 +3241,142 @@ UPB_API_INLINE void upb_Message_SetClosedEnum(
|
|||
const upb_MiniTableField* f, int32_t value) {
|
||||
UPB_ASSERT(upb_MiniTableField_IsClosedEnum(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSERT(upb_MiniTableEnum_CheckValue(
|
||||
upb_MiniTable_GetSubEnumTable(msg_mini_table, f), value));
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
// Extension Setters ///////////////////////////////////////////////////////////
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionBool(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e, bool value,
|
||||
upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Bool);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_1Byte);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionDouble(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e, double value,
|
||||
upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Double);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_8Byte);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionFloat(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e, float value,
|
||||
upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Float);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_4Byte);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionInt32(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e, int32_t value,
|
||||
upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Int32 ||
|
||||
upb_MiniTableExtension_CType(e) == kUpb_CType_Enum);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_4Byte);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionInt64(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e, int64_t value,
|
||||
upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Int64);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_8Byte);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionString(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e,
|
||||
upb_StringView value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_String ||
|
||||
upb_MiniTableExtension_CType(e) == kUpb_CType_Bytes);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_StringView);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionUInt32(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e, uint32_t value,
|
||||
upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_UInt32);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_4Byte);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionUInt64(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e, uint64_t value,
|
||||
upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_UInt64);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_8Byte);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
// Universal Setters ///////////////////////////////////////////////////////////
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetBool(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f, bool value,
|
||||
upb_Arena* a) {
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionBool(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldBool(msg, f, value), true);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetDouble(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
double value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Double);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.double_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionDouble(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldDouble(msg, f, value), true);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetFloat(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
float value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Float);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.float_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionFloat(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldFloat(msg, f, value), true);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetInt32(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
int32_t value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int32 ||
|
||||
upb_MiniTableField_CType(f) == kUpb_CType_Enum);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.int32_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionInt32(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldInt32(msg, f, value), true);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetInt64(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
int64_t value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int64);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.int64_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionInt64(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldInt64(msg, f, value), true);
|
||||
}
|
||||
|
||||
// Sets the value of a message-typed field. The mini_tables of `msg` and
|
||||
// `sub_message` must have been linked for this to work correctly.
|
||||
UPB_API_INLINE void upb_Message_SetMessage(struct upb_Message* msg,
|
||||
const upb_MiniTable* m,
|
||||
const upb_MiniTableField* f,
|
||||
struct upb_Message* sub_message) {
|
||||
UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)
|
||||
(msg, f, UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(sub_message, false));
|
||||
}
|
||||
|
||||
// Sets the value of a `string` or `bytes` field. The bytes of the value are not
|
||||
|
@ -3198,36 +3386,28 @@ UPB_API_INLINE bool upb_Message_SetInt64(struct upb_Message* msg,
|
|||
UPB_API_INLINE bool upb_Message_SetString(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
upb_StringView value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_String ||
|
||||
upb_MiniTableField_CType(f) == kUpb_CType_Bytes);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
|
||||
kUpb_FieldRep_StringView);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.str_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionString(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldString(msg, f, value), true);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetUInt32(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
uint32_t value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt32);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.uint32_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionUInt32(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldUInt32(msg, f, value), true);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetUInt64(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
uint64_t value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt64);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.uint64_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionUInt64(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldUInt64(msg, f, value), true);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_Clear(struct upb_Message* msg,
|
||||
|
@ -3506,41 +3686,6 @@ UPB_API_INLINE upb_Message* upb_TaggedMessagePtr_GetNonEmptyMessage(
|
|||
|
||||
#endif /* UPB_MINI_TABLE_TAGGED_PTR_H_ */
|
||||
|
||||
#ifndef UPB_MINI_TABLE_SUB_H_
|
||||
#define UPB_MINI_TABLE_SUB_H_
|
||||
|
||||
|
||||
// Must be last.
|
||||
|
||||
typedef union upb_MiniTableSub upb_MiniTableSub;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Constructors
|
||||
|
||||
UPB_API_INLINE upb_MiniTableSub
|
||||
upb_MiniTableSub_FromEnum(const upb_MiniTableEnum* subenum);
|
||||
|
||||
UPB_API_INLINE upb_MiniTableSub
|
||||
upb_MiniTableSub_FromMessage(const upb_MiniTable* submsg);
|
||||
|
||||
// Getters
|
||||
|
||||
UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableSub_Enum(
|
||||
upb_MiniTableSub sub);
|
||||
|
||||
UPB_API_INLINE const upb_MiniTable* upb_MiniTableSub_Message(
|
||||
upb_MiniTableSub sub);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* UPB_MINI_TABLE_SUB_H_ */
|
||||
|
||||
// Must be last.
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -3583,6 +3728,10 @@ UPB_API_INLINE upb_MessageValue
|
|||
upb_Message_GetField(const upb_Message* msg, const upb_MiniTableField* f,
|
||||
upb_MessageValue default_val);
|
||||
|
||||
UPB_API_INLINE upb_TaggedMessagePtr upb_Message_GetTaggedMessagePtr(
|
||||
const upb_Message* msg, const upb_MiniTableField* field,
|
||||
upb_Message* default_val);
|
||||
|
||||
UPB_API_INLINE const upb_Array* upb_Message_GetArray(
|
||||
const upb_Message* msg, const upb_MiniTableField* f);
|
||||
|
||||
|
@ -3609,12 +3758,18 @@ UPB_API_INLINE int64_t upb_Message_GetInt64(const upb_Message* msg,
|
|||
UPB_API_INLINE const upb_Map* upb_Message_GetMap(const upb_Message* msg,
|
||||
const upb_MiniTableField* f);
|
||||
|
||||
UPB_API_INLINE const upb_Message* upb_Message_GetMessage(
|
||||
const upb_Message* msg, const upb_MiniTableField* f);
|
||||
|
||||
UPB_API_INLINE upb_Array* upb_Message_GetMutableArray(
|
||||
upb_Message* msg, const upb_MiniTableField* f);
|
||||
|
||||
UPB_API_INLINE upb_Map* upb_Message_GetMutableMap(upb_Message* msg,
|
||||
const upb_MiniTableField* f);
|
||||
|
||||
UPB_API_INLINE upb_Message* upb_Message_GetMutableMessage(
|
||||
upb_Message* msg, const upb_MiniTableField* f);
|
||||
|
||||
UPB_API_INLINE upb_Array* upb_Message_GetOrCreateMutableArray(
|
||||
upb_Message* msg, const upb_MiniTableField* f, upb_Arena* arena);
|
||||
|
||||
|
@ -3662,6 +3817,11 @@ UPB_API_INLINE bool upb_Message_SetInt64(upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
int64_t value, upb_Arena* a);
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetMessage(upb_Message* msg,
|
||||
const upb_MiniTable* m,
|
||||
const upb_MiniTableField* f,
|
||||
upb_Message* sub_message);
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetString(upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
upb_StringView value, upb_Arena* a);
|
||||
|
@ -3674,55 +3834,6 @@ UPB_API_INLINE bool upb_Message_SetUInt64(upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
uint64_t value, upb_Arena* a);
|
||||
|
||||
UPB_API_INLINE upb_TaggedMessagePtr upb_Message_GetTaggedMessagePtr(
|
||||
const upb_Message* msg, const upb_MiniTableField* field,
|
||||
upb_Message* default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Message);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) ==
|
||||
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(field));
|
||||
upb_TaggedMessagePtr tagged;
|
||||
_upb_Message_GetNonExtensionField(msg, field, &default_val, &tagged);
|
||||
return tagged;
|
||||
}
|
||||
|
||||
UPB_API_INLINE const upb_Message* upb_Message_GetMessage(
|
||||
const upb_Message* msg, const upb_MiniTableField* field) {
|
||||
upb_TaggedMessagePtr tagged =
|
||||
upb_Message_GetTaggedMessagePtr(msg, field, NULL);
|
||||
return upb_TaggedMessagePtr_GetNonEmptyMessage(tagged);
|
||||
}
|
||||
|
||||
UPB_API_INLINE upb_Message* upb_Message_GetMutableMessage(
|
||||
upb_Message* msg, const upb_MiniTableField* field) {
|
||||
return (upb_Message*)upb_Message_GetMessage(msg, field);
|
||||
}
|
||||
|
||||
// For internal use only; users cannot set tagged messages because only the
|
||||
// parser and the message copier are allowed to directly create an empty
|
||||
// message.
|
||||
UPB_INLINE void UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)(
|
||||
struct upb_Message* msg, const upb_MiniTable* mini_table,
|
||||
const upb_MiniTableField* f, upb_TaggedMessagePtr sub_message) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
|
||||
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_Message_SetBaseField(msg, f, &sub_message);
|
||||
}
|
||||
|
||||
// Sets the value of a message-typed field. The `mini_table` and `field`
|
||||
// parameters belong to `msg`, not `sub_message`. The mini_tables of `msg` and
|
||||
// `sub_message` must have been linked for this to work correctly.
|
||||
UPB_API_INLINE void upb_Message_SetMessage(upb_Message* msg,
|
||||
const upb_MiniTable* mini_table,
|
||||
const upb_MiniTableField* field,
|
||||
upb_Message* sub_message) {
|
||||
UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)
|
||||
(msg, mini_table, field,
|
||||
UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(sub_message, false));
|
||||
}
|
||||
|
||||
UPB_API_INLINE void* upb_Message_ResizeArrayUninitialized(
|
||||
upb_Message* msg, const upb_MiniTableField* f, size_t size,
|
||||
upb_Arena* arena);
|
||||
|
@ -3795,6 +3906,41 @@ UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val,
|
|||
#define UPB_MINI_TABLE_DECODE_H_
|
||||
|
||||
|
||||
#ifndef UPB_MINI_TABLE_SUB_H_
|
||||
#define UPB_MINI_TABLE_SUB_H_
|
||||
|
||||
|
||||
// Must be last.
|
||||
|
||||
typedef union upb_MiniTableSub upb_MiniTableSub;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Constructors
|
||||
|
||||
UPB_API_INLINE upb_MiniTableSub
|
||||
upb_MiniTableSub_FromEnum(const upb_MiniTableEnum* subenum);
|
||||
|
||||
UPB_API_INLINE upb_MiniTableSub
|
||||
upb_MiniTableSub_FromMessage(const upb_MiniTable* submsg);
|
||||
|
||||
// Getters
|
||||
|
||||
UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableSub_Enum(
|
||||
upb_MiniTableSub sub);
|
||||
|
||||
UPB_API_INLINE const upb_MiniTable* upb_MiniTableSub_Message(
|
||||
upb_MiniTableSub sub);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* UPB_MINI_TABLE_SUB_H_ */
|
||||
|
||||
// Export the newer headers, for legacy users. New users should include the
|
||||
// more specific headers directly.
|
||||
// IWYU pragma: begin_exports
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
//! Tests covering accessors for singular bool, int32, int64, and bytes fields.
|
||||
|
||||
use googletest::prelude::*;
|
||||
use protobuf::{MutProxy, Optional};
|
||||
use protobuf::Optional;
|
||||
use unittest_proto::{test_all_types, TestAllTypes};
|
||||
|
||||
#[test]
|
||||
|
@ -498,15 +498,13 @@ fn test_nonempty_default_string_accessors() {
|
|||
|
||||
#[test]
|
||||
fn test_singular_msg_field() {
|
||||
use test_all_types::*;
|
||||
|
||||
let mut msg = TestAllTypes::new();
|
||||
let msg_view = msg.optional_nested_message();
|
||||
// testing reading an int inside a view
|
||||
assert_that!(msg_view.bb(), eq(0));
|
||||
|
||||
assert_that!(msg.has_optional_nested_message(), eq(false));
|
||||
let mut nested_msg_mut = msg.optional_nested_message_mut();
|
||||
let nested_msg_mut = msg.optional_nested_message_mut();
|
||||
// test reading an int inside a mut
|
||||
assert_that!(nested_msg_mut.bb(), eq(0));
|
||||
|
||||
|
@ -780,3 +778,27 @@ fn test_submsg_setter() {
|
|||
|
||||
assert_that!(parent.optional_nested_message().bb(), eq(7));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_owned() {
|
||||
let mut m = TestAllTypes::new();
|
||||
m.set_optional_int32(42);
|
||||
let clone = m.as_view().to_owned();
|
||||
assert_that!(clone.optional_int32(), eq(42));
|
||||
|
||||
// to_owned should create a new message (modifying the original shouldn't affect
|
||||
// the to_owned).
|
||||
m.clear_optional_int32();
|
||||
assert_that!(m.has_optional_int32(), eq(false));
|
||||
assert_that!(clone.has_optional_int32(), eq(true));
|
||||
assert_that!(clone.optional_int32(), eq(42));
|
||||
|
||||
let mut submsg_mut = m.optional_nested_message_mut();
|
||||
submsg_mut.set_bb(7);
|
||||
let submsg_clone = submsg_mut.to_owned();
|
||||
assert_that!(submsg_clone.bb(), eq(7));
|
||||
assert_that!(submsg_mut.bb(), eq(7));
|
||||
submsg_mut.set_bb(8);
|
||||
assert_that!(submsg_clone.bb(), eq(7));
|
||||
assert_that!(submsg_mut.bb(), eq(8));
|
||||
}
|
||||
|
|
|
@ -840,6 +840,16 @@ filegroup(
|
|||
visibility = ["//:__subpackages__"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "unittest_proto_srcs",
|
||||
srcs = [
|
||||
"unittest.proto",
|
||||
"unittest_import.proto",
|
||||
"unittest_import_public.proto",
|
||||
],
|
||||
visibility = ["//:__subpackages__"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "test_proto_editions_srcs",
|
||||
srcs = [
|
||||
|
|
|
@ -469,7 +469,7 @@ class PROTOC_EXPORT CommandLineInterface {
|
|||
// When using --encode, this will be passed to SetSerializationDeterministic.
|
||||
bool deterministic_output_ = false;
|
||||
|
||||
bool opensource_runtime_ = PROTO2_IS_OSS;
|
||||
bool opensource_runtime_ = google::protobuf::internal::IsOss();
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "google/protobuf/compiler/code_generator.h"
|
||||
#include "google/protobuf/cpp_features.pb.h"
|
||||
#include "google/protobuf/descriptor.pb.h"
|
||||
#include "google/protobuf/port.h"
|
||||
|
||||
// Must be included last.
|
||||
#include "google/protobuf/port_def.inc"
|
||||
|
@ -85,7 +86,7 @@ class PROTOC_EXPORT CppGenerator : public CodeGenerator {
|
|||
using CodeGenerator::GetResolvedSourceFeatures;
|
||||
|
||||
private:
|
||||
bool opensource_runtime_ = PROTO2_IS_OSS;
|
||||
bool opensource_runtime_ = google::protobuf::internal::IsOss();
|
||||
std::string runtime_include_base_;
|
||||
|
||||
absl::Status ValidateFeatures(const FileDescriptor* file) const;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "google/protobuf/compiler/code_generator.h"
|
||||
#include "google/protobuf/compiler/java/java_features.pb.h"
|
||||
#include "google/protobuf/descriptor.pb.h"
|
||||
#include "google/protobuf/port.h"
|
||||
|
||||
// Must be included last.
|
||||
#include "google/protobuf/port_def.inc"
|
||||
|
@ -62,7 +63,7 @@ class PROTOC_EXPORT JavaGenerator : public CodeGenerator {
|
|||
using CodeGenerator::GetResolvedSourceFeatures;
|
||||
|
||||
private:
|
||||
bool opensource_runtime_ = PROTO2_IS_OSS;
|
||||
bool opensource_runtime_ = google::protobuf::internal::IsOss();
|
||||
};
|
||||
|
||||
} // namespace java
|
||||
|
|
|
@ -39,16 +39,17 @@ const char* DefaultPackage(Options options) {
|
|||
bool IsReservedName(absl::string_view name) {
|
||||
static const auto& kReservedNames =
|
||||
*new absl::flat_hash_set<absl::string_view>({
|
||||
"abstract", "assert", "boolean", "break", "byte",
|
||||
"case", "catch", "char", "class", "const",
|
||||
"continue", "default", "do", "double", "else",
|
||||
"enum", "extends", "final", "finally", "float",
|
||||
"for", "goto", "if", "implements", "import",
|
||||
"instanceof", "int", "interface", "long", "native",
|
||||
"new", "package", "private", "protected", "public",
|
||||
"return", "short", "static", "strictfp", "super",
|
||||
"switch", "synchronized", "this", "throw", "throws",
|
||||
"transient", "try", "void", "volatile", "while",
|
||||
"abstract", "assert", "boolean", "break", "byte",
|
||||
"case", "catch", "char", "class", "const",
|
||||
"continue", "default", "do", "double", "else",
|
||||
"enum", "extends", "false", "final", "finally",
|
||||
"float", "for", "goto", "if", "implements",
|
||||
"import", "instanceof", "int", "interface", "long",
|
||||
"native", "new", "package", "private", "protected",
|
||||
"public", "return", "short", "static", "strictfp",
|
||||
"super", "switch", "synchronized", "this", "throw",
|
||||
"throws", "transient", "true", "try", "void",
|
||||
"volatile", "while",
|
||||
});
|
||||
return kReservedNames.contains(name);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "google/protobuf/port_def.inc"
|
||||
#include "google/protobuf/port.h"
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
|
@ -34,7 +34,7 @@ struct Options {
|
|||
// When set, the protoc will generate the current files and all the transitive
|
||||
// dependencies as lite runtime.
|
||||
bool enforce_lite;
|
||||
bool opensource_runtime = PROTO2_IS_OSS;
|
||||
bool opensource_runtime = google::protobuf::internal::IsOss();
|
||||
// If true, we should build .meta files and emit @Generated annotations into
|
||||
// generated code.
|
||||
bool annotate_code;
|
||||
|
@ -53,5 +53,4 @@ struct Options {
|
|||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include "google/protobuf/port_undef.inc"
|
||||
#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_OPTIONS_H__
|
||||
|
|
|
@ -911,6 +911,10 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
|
|||
$Msg::serialize$
|
||||
}
|
||||
|
||||
pub fn to_owned(&self) -> $Msg$ {
|
||||
$pb$::IntoProxied::into(*self, $pbi$::Private)
|
||||
}
|
||||
|
||||
$accessor_fns_for_views$
|
||||
}
|
||||
|
||||
|
@ -986,6 +990,10 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
|
|||
$pb$::ViewProxy::as_view(self).serialize()
|
||||
}
|
||||
|
||||
pub fn to_owned(&self) -> $Msg$ {
|
||||
$pb$::ViewProxy::as_view(self).to_owned()
|
||||
}
|
||||
|
||||
$get_upb_minitable$
|
||||
|
||||
$raw_arena_getter_for_msgmut$
|
||||
|
|
|
@ -314,6 +314,8 @@ inline void PrefetchToLocalCache(const void* ptr) {
|
|||
absl::PrefetchToLocalCache(ptr);
|
||||
}
|
||||
|
||||
constexpr bool IsOss() { return true; }
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
|
|
@ -919,8 +919,6 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3),
|
|||
#define PROTOBUF_DEBUG false
|
||||
#endif
|
||||
|
||||
#define PROTO2_IS_OSS true
|
||||
|
||||
#ifdef PROTOBUF_NO_THREADLOCAL
|
||||
#error PROTOBUF_NO_THREADLOCAL was previously defined
|
||||
#endif
|
||||
|
|
|
@ -72,7 +72,6 @@
|
|||
#undef PROTOBUF_PREFETCH_WITH_OFFSET
|
||||
#undef PROTOBUF_TC_PARAM_DECL
|
||||
#undef PROTOBUF_DEBUG
|
||||
#undef PROTO2_IS_OSS
|
||||
#undef PROTOBUF_NO_THREADLOCAL
|
||||
|
||||
#ifdef PROTOBUF_FUTURE_BREAKING_CHANGES
|
||||
|
|
|
@ -8,30 +8,17 @@
|
|||
#ifndef UPB_MESSAGE_ACCESSORS_H_
|
||||
#define UPB_MESSAGE_ACCESSORS_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "upb/base/descriptor_constants.h"
|
||||
#include "upb/base/string_view.h"
|
||||
#include "upb/mem/arena.h"
|
||||
#include "upb/message/array.h"
|
||||
#include "upb/message/internal/accessors.h"
|
||||
#include "upb/message/internal/array.h"
|
||||
#include "upb/message/internal/map.h"
|
||||
#include "upb/message/internal/message.h"
|
||||
#include "upb/message/internal/tagged_ptr.h"
|
||||
#include "upb/message/map.h"
|
||||
#include "upb/message/message.h"
|
||||
#include "upb/message/tagged_ptr.h"
|
||||
#include "upb/message/value.h"
|
||||
#include "upb/mini_table/enum.h"
|
||||
#include "upb/mini_table/extension.h"
|
||||
#include "upb/mini_table/field.h"
|
||||
#include "upb/mini_table/internal/field.h"
|
||||
#include "upb/mini_table/internal/message.h"
|
||||
#include "upb/mini_table/message.h"
|
||||
#include "upb/mini_table/sub.h"
|
||||
|
||||
// Must be last.
|
||||
#include "upb/port/def.inc"
|
||||
|
@ -76,6 +63,10 @@ UPB_API_INLINE upb_MessageValue
|
|||
upb_Message_GetField(const upb_Message* msg, const upb_MiniTableField* f,
|
||||
upb_MessageValue default_val);
|
||||
|
||||
UPB_API_INLINE upb_TaggedMessagePtr upb_Message_GetTaggedMessagePtr(
|
||||
const upb_Message* msg, const upb_MiniTableField* field,
|
||||
upb_Message* default_val);
|
||||
|
||||
UPB_API_INLINE const upb_Array* upb_Message_GetArray(
|
||||
const upb_Message* msg, const upb_MiniTableField* f);
|
||||
|
||||
|
@ -102,12 +93,18 @@ UPB_API_INLINE int64_t upb_Message_GetInt64(const upb_Message* msg,
|
|||
UPB_API_INLINE const upb_Map* upb_Message_GetMap(const upb_Message* msg,
|
||||
const upb_MiniTableField* f);
|
||||
|
||||
UPB_API_INLINE const upb_Message* upb_Message_GetMessage(
|
||||
const upb_Message* msg, const upb_MiniTableField* f);
|
||||
|
||||
UPB_API_INLINE upb_Array* upb_Message_GetMutableArray(
|
||||
upb_Message* msg, const upb_MiniTableField* f);
|
||||
|
||||
UPB_API_INLINE upb_Map* upb_Message_GetMutableMap(upb_Message* msg,
|
||||
const upb_MiniTableField* f);
|
||||
|
||||
UPB_API_INLINE upb_Message* upb_Message_GetMutableMessage(
|
||||
upb_Message* msg, const upb_MiniTableField* f);
|
||||
|
||||
UPB_API_INLINE upb_Array* upb_Message_GetOrCreateMutableArray(
|
||||
upb_Message* msg, const upb_MiniTableField* f, upb_Arena* arena);
|
||||
|
||||
|
@ -155,6 +152,11 @@ UPB_API_INLINE bool upb_Message_SetInt64(upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
int64_t value, upb_Arena* a);
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetMessage(upb_Message* msg,
|
||||
const upb_MiniTable* m,
|
||||
const upb_MiniTableField* f,
|
||||
upb_Message* sub_message);
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetString(upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
upb_StringView value, upb_Arena* a);
|
||||
|
@ -167,55 +169,6 @@ UPB_API_INLINE bool upb_Message_SetUInt64(upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
uint64_t value, upb_Arena* a);
|
||||
|
||||
UPB_API_INLINE upb_TaggedMessagePtr upb_Message_GetTaggedMessagePtr(
|
||||
const upb_Message* msg, const upb_MiniTableField* field,
|
||||
upb_Message* default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Message);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) ==
|
||||
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(field));
|
||||
upb_TaggedMessagePtr tagged;
|
||||
_upb_Message_GetNonExtensionField(msg, field, &default_val, &tagged);
|
||||
return tagged;
|
||||
}
|
||||
|
||||
UPB_API_INLINE const upb_Message* upb_Message_GetMessage(
|
||||
const upb_Message* msg, const upb_MiniTableField* field) {
|
||||
upb_TaggedMessagePtr tagged =
|
||||
upb_Message_GetTaggedMessagePtr(msg, field, NULL);
|
||||
return upb_TaggedMessagePtr_GetNonEmptyMessage(tagged);
|
||||
}
|
||||
|
||||
UPB_API_INLINE upb_Message* upb_Message_GetMutableMessage(
|
||||
upb_Message* msg, const upb_MiniTableField* field) {
|
||||
return (upb_Message*)upb_Message_GetMessage(msg, field);
|
||||
}
|
||||
|
||||
// For internal use only; users cannot set tagged messages because only the
|
||||
// parser and the message copier are allowed to directly create an empty
|
||||
// message.
|
||||
UPB_INLINE void UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)(
|
||||
struct upb_Message* msg, const upb_MiniTable* mini_table,
|
||||
const upb_MiniTableField* f, upb_TaggedMessagePtr sub_message) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
|
||||
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_Message_SetBaseField(msg, f, &sub_message);
|
||||
}
|
||||
|
||||
// Sets the value of a message-typed field. The `mini_table` and `field`
|
||||
// parameters belong to `msg`, not `sub_message`. The mini_tables of `msg` and
|
||||
// `sub_message` must have been linked for this to work correctly.
|
||||
UPB_API_INLINE void upb_Message_SetMessage(upb_Message* msg,
|
||||
const upb_MiniTable* mini_table,
|
||||
const upb_MiniTableField* field,
|
||||
upb_Message* sub_message) {
|
||||
UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)
|
||||
(msg, mini_table, field,
|
||||
UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(sub_message, false));
|
||||
}
|
||||
|
||||
UPB_API_INLINE void* upb_Message_ResizeArrayUninitialized(
|
||||
upb_Message* msg, const upb_MiniTableField* f, size_t size,
|
||||
upb_Arena* arena);
|
||||
|
|
|
@ -215,7 +215,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
|
|||
return NULL;
|
||||
}
|
||||
UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)
|
||||
(dst, mini_table, field,
|
||||
(dst, field,
|
||||
UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(dst_sub_message,
|
||||
is_empty));
|
||||
}
|
||||
|
|
|
@ -220,7 +220,6 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(
|
|||
// const upb_MiniTableField* field,
|
||||
// bool value, upb_Arena* a) {
|
||||
// UPB_ASSUME(field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Bool);
|
||||
// UPB_ASSUME(upb_MiniTableField_IsScalar(field));
|
||||
// UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) ==
|
||||
// kUpb_FieldRep_1Byte);
|
||||
// upb_Message_SetField(msg, field, &value, a);
|
||||
|
@ -351,8 +350,8 @@ UPB_API_INLINE bool upb_Message_GetBool(const struct upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
bool default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Bool);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
|
||||
upb_MessageValue def;
|
||||
def.bool_val = default_val;
|
||||
return upb_Message_GetField(msg, f, def).bool_val;
|
||||
|
@ -362,8 +361,8 @@ UPB_API_INLINE double upb_Message_GetDouble(const struct upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
double default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Double);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
|
||||
upb_MessageValue def;
|
||||
def.double_val = default_val;
|
||||
|
@ -374,8 +373,8 @@ UPB_API_INLINE float upb_Message_GetFloat(const struct upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
float default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Float);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
|
||||
upb_MessageValue def;
|
||||
def.float_val = default_val;
|
||||
|
@ -387,8 +386,8 @@ UPB_API_INLINE int32_t upb_Message_GetInt32(const struct upb_Message* msg,
|
|||
int32_t default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int32 ||
|
||||
upb_MiniTableField_CType(f) == kUpb_CType_Enum);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
|
||||
upb_MessageValue def;
|
||||
def.int32_val = default_val;
|
||||
|
@ -399,8 +398,8 @@ UPB_API_INLINE int64_t upb_Message_GetInt64(const struct upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
int64_t default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int64);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
|
||||
upb_MessageValue def;
|
||||
def.int64_val = default_val;
|
||||
|
@ -429,6 +428,37 @@ UPB_API_INLINE const struct upb_Map* upb_Message_GetMap(
|
|||
return ret;
|
||||
}
|
||||
|
||||
UPB_API_INLINE uintptr_t upb_Message_GetTaggedMessagePtr(
|
||||
const struct upb_Message* msg, const upb_MiniTableField* f,
|
||||
struct upb_Message* default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
|
||||
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
uintptr_t tagged;
|
||||
_upb_Message_GetNonExtensionField(msg, f, &default_val, &tagged);
|
||||
return tagged;
|
||||
}
|
||||
|
||||
// For internal use only; users cannot set tagged messages because only the
|
||||
// parser and the message copier are allowed to directly create an empty
|
||||
// message.
|
||||
UPB_INLINE void UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)(
|
||||
struct upb_Message* msg, const upb_MiniTableField* f,
|
||||
uintptr_t sub_message) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
|
||||
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_Message_SetBaseField(msg, f, &sub_message);
|
||||
}
|
||||
|
||||
UPB_API_INLINE const struct upb_Message* upb_Message_GetMessage(
|
||||
const struct upb_Message* msg, const upb_MiniTableField* f) {
|
||||
uintptr_t tagged = upb_Message_GetTaggedMessagePtr(msg, f, NULL);
|
||||
return upb_TaggedMessagePtr_GetNonEmptyMessage(tagged);
|
||||
}
|
||||
|
||||
UPB_API_INLINE upb_Array* upb_Message_GetMutableArray(
|
||||
struct upb_Message* msg, const upb_MiniTableField* f) {
|
||||
UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(f);
|
||||
|
@ -440,6 +470,11 @@ UPB_API_INLINE struct upb_Map* upb_Message_GetMutableMap(
|
|||
return (struct upb_Map*)upb_Message_GetMap(msg, f);
|
||||
}
|
||||
|
||||
UPB_API_INLINE struct upb_Message* upb_Message_GetMutableMessage(
|
||||
struct upb_Message* msg, const upb_MiniTableField* f) {
|
||||
return (struct upb_Message*)upb_Message_GetMessage(msg, f);
|
||||
}
|
||||
|
||||
UPB_API_INLINE upb_Array* upb_Message_GetOrCreateMutableArray(
|
||||
struct upb_Message* msg, const upb_MiniTableField* f, upb_Arena* arena) {
|
||||
UPB_ASSERT(arena);
|
||||
|
@ -515,7 +550,6 @@ upb_Message_GetString(const struct upb_Message* msg,
|
|||
upb_MiniTableField_CType(f) == kUpb_CType_Bytes);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
|
||||
kUpb_FieldRep_StringView);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
|
||||
upb_MessageValue def;
|
||||
def.str_val = default_val;
|
||||
|
@ -526,8 +560,8 @@ UPB_API_INLINE uint32_t upb_Message_GetUInt32(const struct upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
uint32_t default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt32);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
|
||||
upb_MessageValue def;
|
||||
def.uint32_val = default_val;
|
||||
|
@ -538,23 +572,89 @@ UPB_API_INLINE uint64_t upb_Message_GetUInt64(const struct upb_Message* msg,
|
|||
const upb_MiniTableField* f,
|
||||
uint64_t default_val) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt64);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
|
||||
upb_MessageValue def;
|
||||
def.uint64_val = default_val;
|
||||
return upb_Message_GetField(msg, f, def).uint64_val;
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetBool(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f, bool value,
|
||||
upb_Arena* a) {
|
||||
// BaseField Setters ///////////////////////////////////////////////////////////
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldBool(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
bool value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Bool);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.bool_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldDouble(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
double value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Double);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldFloat(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
float value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Float);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldInt32(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
int32_t value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int32 ||
|
||||
upb_MiniTableField_CType(f) == kUpb_CType_Enum);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldInt64(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
int64_t value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int64);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldString(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
upb_StringView value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_String ||
|
||||
upb_MiniTableField_CType(f) == kUpb_CType_Bytes);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
|
||||
kUpb_FieldRep_StringView);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldUInt32(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
uint32_t value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt32);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetBaseFieldUInt64(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
uint64_t value) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt64);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_SetClosedEnum(
|
||||
|
@ -562,55 +662,142 @@ UPB_API_INLINE void upb_Message_SetClosedEnum(
|
|||
const upb_MiniTableField* f, int32_t value) {
|
||||
UPB_ASSERT(upb_MiniTableField_IsClosedEnum(f));
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
UPB_ASSERT(upb_MiniTableEnum_CheckValue(
|
||||
upb_MiniTable_GetSubEnumTable(msg_mini_table, f), value));
|
||||
upb_Message_SetBaseField(msg, f, &value);
|
||||
}
|
||||
|
||||
// Extension Setters ///////////////////////////////////////////////////////////
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionBool(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e, bool value,
|
||||
upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Bool);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_1Byte);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionDouble(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e, double value,
|
||||
upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Double);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_8Byte);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionFloat(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e, float value,
|
||||
upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Float);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_4Byte);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionInt32(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e, int32_t value,
|
||||
upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Int32 ||
|
||||
upb_MiniTableExtension_CType(e) == kUpb_CType_Enum);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_4Byte);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionInt64(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e, int64_t value,
|
||||
upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Int64);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_8Byte);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionString(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e,
|
||||
upb_StringView value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_String ||
|
||||
upb_MiniTableExtension_CType(e) == kUpb_CType_Bytes);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_StringView);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionUInt32(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e, uint32_t value,
|
||||
upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_UInt32);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_4Byte);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetExtensionUInt64(
|
||||
struct upb_Message* msg, const upb_MiniTableExtension* e, uint64_t value,
|
||||
upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_UInt64);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
||||
kUpb_FieldRep_8Byte);
|
||||
return upb_Message_SetExtension(msg, e, &value, a);
|
||||
}
|
||||
|
||||
// Universal Setters ///////////////////////////////////////////////////////////
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetBool(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f, bool value,
|
||||
upb_Arena* a) {
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionBool(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldBool(msg, f, value), true);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetDouble(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
double value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Double);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.double_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionDouble(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldDouble(msg, f, value), true);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetFloat(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
float value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Float);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.float_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionFloat(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldFloat(msg, f, value), true);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetInt32(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
int32_t value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int32 ||
|
||||
upb_MiniTableField_CType(f) == kUpb_CType_Enum);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.int32_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionInt32(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldInt32(msg, f, value), true);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetInt64(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
int64_t value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int64);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.int64_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionInt64(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldInt64(msg, f, value), true);
|
||||
}
|
||||
|
||||
// Sets the value of a message-typed field. The mini_tables of `msg` and
|
||||
// `sub_message` must have been linked for this to work correctly.
|
||||
UPB_API_INLINE void upb_Message_SetMessage(struct upb_Message* msg,
|
||||
const upb_MiniTable* m,
|
||||
const upb_MiniTableField* f,
|
||||
struct upb_Message* sub_message) {
|
||||
UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)
|
||||
(msg, f, UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(sub_message, false));
|
||||
}
|
||||
|
||||
// Sets the value of a `string` or `bytes` field. The bytes of the value are not
|
||||
|
@ -620,36 +807,28 @@ UPB_API_INLINE bool upb_Message_SetInt64(struct upb_Message* msg,
|
|||
UPB_API_INLINE bool upb_Message_SetString(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
upb_StringView value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_String ||
|
||||
upb_MiniTableField_CType(f) == kUpb_CType_Bytes);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
|
||||
kUpb_FieldRep_StringView);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.str_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionString(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldString(msg, f, value), true);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetUInt32(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
uint32_t value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt32);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.uint32_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionUInt32(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldUInt32(msg, f, value), true);
|
||||
}
|
||||
|
||||
UPB_API_INLINE bool upb_Message_SetUInt64(struct upb_Message* msg,
|
||||
const upb_MiniTableField* f,
|
||||
uint64_t value, upb_Arena* a) {
|
||||
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt64);
|
||||
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
|
||||
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
|
||||
upb_MessageValue val;
|
||||
val.uint64_val = value;
|
||||
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
|
||||
return upb_MiniTableField_IsExtension(f)
|
||||
? upb_Message_SetExtensionUInt64(
|
||||
msg, (const upb_MiniTableExtension*)f, value, a)
|
||||
: (upb_Message_SetBaseFieldUInt64(msg, f, value), true);
|
||||
}
|
||||
|
||||
UPB_API_INLINE void upb_Message_Clear(struct upb_Message* msg,
|
||||
|
|
|
@ -49,6 +49,11 @@ UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage(
|
|||
e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg) = m;
|
||||
}
|
||||
|
||||
UPB_INLINE upb_FieldRep UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(
|
||||
const struct upb_MiniTableExtension* e) {
|
||||
return UPB_PRIVATE(_upb_MiniTableField_GetRep)(&e->UPB_PRIVATE(field));
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue