Go to the documentation of this file.
35 #include <ruby/encoding.h>
41 #define CHARPTR_AT(msg, ofs) ((char*)msg + ofs)
42 #define DEREF_OFFSET(msg, ofs, type) *(type*)CHARPTR_AT(msg, ofs)
43 #define DEREF(memory, type) *(type*)(memory)
70 rb_raise(
cTypeError,
"Expected number type for integral field '%s' (given %s).",
71 name, rb_class2name(CLASS_OF(val)));
77 if (
TYPE(val) == T_FLOAT) {
78 double dbl_val = NUM2DBL(val);
79 if (floor(dbl_val) != dbl_val) {
80 rb_raise(rb_eRangeError,
81 "Non-integral floating point value assigned to integer field '%s' (given %s).",
82 name, rb_class2name(CLASS_OF(val)));
86 if (NUM2DBL(val) < 0) {
87 rb_raise(rb_eRangeError,
88 "Assigning negative value to unsigned integer field '%s' (given %s).",
89 name, rb_class2name(CLASS_OF(val)));
97 VALUE desired_encoding_value = rb_enc_from_encoding(desired_encoding);
99 if (rb_obj_encoding(
value) != desired_encoding_value || !OBJ_FROZEN(
value)) {
101 value = rb_str_encode(
value, desired_encoding_value, 0, Qnil);
104 rb_enc_str_coderange(
value) == ENC_CODERANGE_BROKEN) {
105 rb_raise(rb_eEncodingError,
"String is invalid UTF-8");
110 rb_obj_freeze(
value);
118 void* memory, VALUE
value) {
124 void* memory, VALUE
value,
134 rb_raise(
cTypeError,
"Expected number type for float field '%s' (given %s).",
141 rb_raise(
cTypeError,
"Expected number type for double field '%s' (given %s).",
148 if (
value == Qtrue) {
150 }
else if (
value == Qfalse) {
153 rb_raise(
cTypeError,
"Invalid argument for boolean field '%s' (given %s).",
160 if (CLASS_OF(
value) == rb_cSymbol) {
161 value = rb_funcall(
value, rb_intern(
"to_s"), 0);
162 }
else if (CLASS_OF(
value) != rb_cString) {
163 rb_raise(
cTypeError,
"Invalid argument for string field '%s' (given %s).",
171 if (CLASS_OF(
value) != rb_cString) {
172 rb_raise(
cTypeError,
"Invalid argument for bytes field '%s' (given %s).",
180 if (CLASS_OF(
value) == CLASS_OF(Qnil)) {
182 }
else if (CLASS_OF(
value) != type_class) {
184 VALUE converted_value = Qnil;
185 const char* field_type_name = rb_class2name(type_class);
187 if (strcmp(field_type_name,
"Google::Protobuf::Timestamp") == 0 &&
188 rb_obj_is_kind_of(
value, rb_cTime)) {
190 VALUE
hash = rb_hash_new();
191 rb_hash_aset(
hash, rb_str_new2(
"seconds"),
192 rb_funcall(
value, rb_intern(
"to_i"), 0));
193 rb_hash_aset(
hash, rb_str_new2(
"nanos"),
194 rb_funcall(
value, rb_intern(
"nsec"), 0));
197 converted_value = rb_class_new_instance(1,
args, type_class);
199 }
else if (strcmp(field_type_name,
"Google::Protobuf::Duration") == 0 &&
200 rb_obj_is_kind_of(
value, rb_cNumeric)) {
202 VALUE
hash = rb_hash_new();
203 rb_hash_aset(
hash, rb_str_new2(
"seconds"),
204 rb_funcall(
value, rb_intern(
"to_i"), 0));
207 rb_funcall(
value, rb_intern(
"remainder"), 1, INT2NUM(1));
209 rb_funcall(n_value, rb_intern(
"*"), 1, INT2NUM(1000000000));
210 n_value = rb_funcall(n_value, rb_intern(
"round"), 0);
211 rb_hash_aset(
hash, rb_str_new2(
"nanos"), n_value);
215 converted_value = rb_class_new_instance(1,
args, type_class);
220 if (converted_value == Qnil) {
222 "Invalid type %s to assign to submessage field '%s'.",
225 value = converted_value;
234 value = rb_funcall(
value, rb_intern(
"to_sym"), 0);
237 "Expected number or symbol type for enum field '%s'.",
name);
241 VALUE
lookup = rb_funcall(type_class, rb_intern(
"resolve"), 1,
value);
243 rb_raise(rb_eRangeError,
"Unknown symbol value for enum field '%s'.",
name);
245 int_val = NUM2INT(
lookup);
249 int_val = NUM2INT(
value);
280 if (case_memory != NULL) {
281 *case_memory = case_number;
287 const void* memory) {
290 return DBL2NUM(
DEREF(memory,
float));
292 return DBL2NUM(
DEREF(memory,
double));
298 return DEREF(memory, VALUE);
301 VALUE symbol =
enum_lookup(type_class, INT2NUM(val));
302 if (symbol == Qnil) {
324 DEREF(memory,
float) = 0.0;
327 DEREF(memory,
double) = 0.0;
334 DEREF(memory, VALUE) = rb_str_new2(
"");
339 DEREF(memory, VALUE) = Qnil;
364 rb_gc_mark(
DEREF(memory, VALUE));
380 DEREF(
to, VALUE) = (from_val != Qnil) ?
381 rb_funcall(from_val, rb_intern(
"dup"), 0) : Qnil;
386 DEREF(
to, VALUE) = (from_val != Qnil) ?
402 VALUE
ret = rb_funcall(
val1, rb_intern(
"=="), 1,
val2);
432 if (subdef == NULL)
return false;
451 assert(key_field != NULL);
457 assert(value_field != NULL);
473 return (
offset + granularity - 1) & ~(granularity - 1);
515 off += (hasbit + 8 - 1) / 8;
535 off +=
sizeof(VALUE);
550 off +=
sizeof(VALUE);
567 off +=
sizeof(VALUE);
631 size_t field_size =
sizeof(
uint32_t);
633 off = (off + field_size - 1) & ~(field_size - 1);
660 VALUE type_class = Qnil;
750 if (type_class != Qnil) {
771 if (type_class != Qnil) {
782 DEREF(memory, VALUE) = ary;
802 return ID2SYM(rb_intern(
label));
818 default:
return Qnil;
842 return *((VALUE *)memory);
843 }
else if (!field_set) {
856 if (!RB_TYPE_P(val, T_DATA) || !RTYPEDDATA_P(val) ||
858 rb_raise(
cTypeError,
"Expected repeated field array");
863 rb_raise(
cTypeError,
"Repeated field array has wrong element type");
867 rb_raise(
cTypeError,
"Repeated field array has wrong message/enum class");
877 if (!RB_TYPE_P(val, T_DATA) || !RTYPEDDATA_P(val) ||
878 RTYPEDDATA_TYPE(val) != &
Map_type) {
879 rb_raise(
cTypeError,
"Expected Map instance");
884 rb_raise(
cTypeError,
"Map key type does not match field's key type");
887 rb_raise(
cTypeError,
"Map value type does not match field's value type");
890 rb_raise(
cTypeError,
"Map value type has wrong message/enum class");
931 DEREF(memory, VALUE) = val;
934 DEREF(memory, VALUE) = val;
968 for (
i = 0;
i < noneofs;
i++) {
993 *to_oneof_case = *from_oneof_case;
1027 *to_oneof_case = *from_oneof_case;
1031 DEREF(to_memory, VALUE) =
1034 DEREF(to_memory, VALUE) =
1061 if (*msg1_oneof_case != *msg2_oneof_case ||
1070 DEREF(msg2_memory, VALUE))) {
1075 DEREF(msg2_memory, VALUE))) {
1091 st_index_t h = rb_hash_start(0);
1092 VALUE hash_sym = rb_intern(
"hash");
1098 h = rb_hash_uint(h, NUM2LONG(rb_funcall(field_val, hash_sym, 0)));
1106 VALUE
str = rb_str_new2(
"");
1117 str = rb_str_cat2(
str,
", ");
1122 str = rb_str_cat2(
str,
": ");
1124 str = rb_str_append(
str, rb_funcall(field_val, rb_intern(
"inspect"), 0));
VALUE Map_eq(VALUE _self, VALUE _other)
upb_label_t upb_fielddef_label(const upb_fielddef *f)
bool upb_oneof_done(upb_oneof_iter *iter)
rb_encoding * kRubyStringUtf8Encoding
int64_t upb_fielddef_defaultint64(const upb_fielddef *f)
uint32_t upb_oneofdef_index(const upb_oneofdef *o)
void upb_msg_field_next(upb_msg_field_iter *iter)
double upb_fielddef_defaultdouble(const upb_fielddef *f)
static uint32_t * slot_oneof_case(MessageLayout *layout, const void *storage, const upb_oneofdef *oneof)
VALUE EnumDescriptor_enummodule(VALUE _self)
return memset(p, 0, total)
int upb_msgdef_numoneofs(const upb_msgdef *m)
void native_slot_check_int_range_precision(const char *name, upb_fieldtype_t type, VALUE val)
bool upb_fielddef_issubmsg(const upb_fielddef *f)
float upb_fielddef_defaultfloat(const upb_fielddef *f)
uint32_t upb_fielddef_defaultuint32(const upb_fielddef *f)
#define ALLOC_N(class_name, n)
VALUE layout_eq(MessageLayout *layout, void *msg1, void *msg2)
VALUE native_slot_encode_and_freeze_string(upb_fieldtype_t type, VALUE value)
VALUE layout_get_default(const upb_fielddef *field)
static void slot_clear_hasbit(MessageLayout *layout, const void *storage, const upb_fielddef *field)
bool upb_fielddef_defaultbool(const upb_fielddef *f)
VALUE RepeatedField_new_this_type(VALUE _self)
int32_t upb_fielddef_defaultint32(const upb_fielddef *f)
VALUE field_type_class(const MessageLayout *layout, const upb_fielddef *field)
VALUE RepeatedField_dup(VALUE _self)
void layout_init(MessageLayout *layout, void *storage)
upb_fielddef * upb_msg_iter_field(const upb_msg_field_iter *iter)
upb_fielddef * upb_oneof_iter_field(const upb_oneof_iter *iter)
void layout_mark(MessageLayout *layout, void *storage)
const upb_fielddef * map_field_value(const upb_fielddef *field)
bool native_slot_eq(upb_fieldtype_t type, void *mem1, void *mem2)
bool upb_msg_oneof_done(const upb_msg_oneof_iter *iter)
void create_layout(Descriptor *desc)
static void * slot_memory(MessageLayout *layout, const void *storage, const upb_fielddef *field)
static void slot_set_hasbit(MessageLayout *layout, const void *storage, const upb_fielddef *field)
size_t native_slot_size(upb_fieldtype_t type)
static size_t align_up_to(size_t offset, size_t granularity)
#define NATIVE_SLOT_MAX_SIZE
VALUE RepeatedField_deep_copy(VALUE _self)
VALUE layout_inspect(MessageLayout *layout, void *storage)
const upb_msgdef * upb_fielddef_msgsubdef(const upb_fielddef *f)
VALUE enum_lookup(VALUE self, VALUE number)
static void check_repeated_field_type(const MessageLayout *layout, VALUE val, const upb_fielddef *field)
bool upb_msg_field_done(const upb_msg_field_iter *iter)
void upb_msg_oneof_begin(upb_msg_oneof_iter *iter, const upb_msgdef *m)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static void check_map_field_type(const MessageLayout *layout, VALUE val, const upb_fielddef *field)
void upb_oneof_next(upb_oneof_iter *iter)
void layout_deep_copy(MessageLayout *layout, void *to, void *from)
VALUE Map_new_this_type(VALUE _self)
void upb_oneof_begin(upb_oneof_iter *iter, const upb_oneofdef *o)
VALUE Map_dup(VALUE _self)
const upb_fielddef * map_entry_value(const upb_msgdef *msgdef)
VALUE fieldtype_to_ruby(upb_fieldtype_t type)
#define CHARPTR_AT(msg, ofs)
VALUE Message_deep_copy(VALUE _self)
unsigned __int64 uint64_t
uint32_t upb_fielddef_number(const upb_fielddef *f)
void native_slot_mark(upb_fieldtype_t type, void *memory)
bool upb_fielddef_isstring(const upb_fielddef *f)
const char * upb_enumdef_iton(const upb_enumdef *def, int32_t num)
#define MESSAGE_FIELD_NO_HASBIT
bool upb_fielddef_ismap(const upb_fielddef *f)
void native_slot_set_value_and_case(const char *name, upb_fieldtype_t type, VALUE type_class, void *memory, VALUE value, uint32_t *case_memory, uint32_t case_number)
VALUE layout_hash(MessageLayout *layout, void *storage)
VALUE Map_deep_copy(VALUE _self)
const upb_oneofdef * upb_msg_iter_oneof(const upb_msg_oneof_iter *iter)
int upb_msgdef_numfields(const upb_msgdef *m)
const upb_fielddef * upb_msgdef_itof(const upb_msgdef *m, uint32_t i)
void native_slot_deep_copy(upb_fieldtype_t type, void *to, void *from)
const upb_fielddef * map_entry_key(const upb_msgdef *msgdef)
uint32_t upb_fielddef_index(const upb_fielddef *f)
bool is_map_field(const upb_fielddef *field)
void layout_set(MessageLayout *layout, void *storage, const upb_fielddef *field, VALUE val)
void native_slot_set(const char *name, upb_fieldtype_t type, VALUE type_class, void *memory, VALUE value)
const FieldDescriptor * field
const upb_msgdef * tryget_map_entry_msgdef(const upb_fielddef *field)
static bool is_ruby_num(VALUE value)
void layout_dup(MessageLayout *layout, void *to, void *from)
const upb_msgdef * msgdef
VALUE get_enumdef_obj(VALUE descriptor_pool, const upb_enumdef *def)
bool field_contains_hasbit(MessageLayout *layout, const upb_fielddef *field)
static bool slot_is_hasbit_set(MessageLayout *layout, const void *storage, const upb_fielddef *field)
bool upb_fielddef_haspresence(const upb_fielddef *f)
#define ALLOC(class_name)
void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m)
const upb_enumdef * upb_fielddef_enumsubdef(const upb_fielddef *f)
UniquePtr< SSL_SESSION > ret
const rb_data_type_t RepeatedField_type
RepeatedField * ruby_to_RepeatedField(VALUE value)
const upb_msgdef * msgdef
#define DEREF(memory, type)
upb_syntax_t upb_msgdef_syntax(const upb_msgdef *m)
Map * ruby_to_Map(VALUE _self)
rb_encoding * kRubyString8bitEncoding
std::array< int64_t, Size > values
const upb_fielddef * map_field_key(const upb_fielddef *field)
const upb_enumdef * enumdef
VALUE Descriptor_msgclass(VALUE _self)
static bool lookup(const upb_table *t, lookupkey_t key, upb_value *v, uint32_t hash, eqlfunc_t *eql)
void layout_clear(MessageLayout *layout, const void *storage, const upb_fielddef *field)
void free_layout(MessageLayout *layout)
void upb_msg_oneof_next(upb_msg_oneof_iter *iter)
#define DEREF_OFFSET(msg, ofs, type)
const upb_oneofdef * upb_fielddef_containingoneof(const upb_fielddef *f)
void native_slot_init(upb_fieldtype_t type, void *memory)
bool upb_msgdef_mapentry(const upb_msgdef *m)
bool is_value_field(const upb_fielddef *f)
const upb_msgdef * map_entry_msgdef(const upb_fielddef *field)
VALUE layout_get(MessageLayout *layout, const void *storage, const upb_fielddef *field)
VALUE get_frozen_string(const char *str, size_t size, bool binary)
VALUE RepeatedField_eq(VALUE _self, VALUE _other)
PHP_PROTO_OBJECT_FREE_END PHP_PROTO_OBJECT_DTOR_END intern self
bool upb_fielddef_isseq(const upb_fielddef *f)
void native_slot_dup(upb_fieldtype_t type, void *to, void *from)
uint32_t slot_read_oneof_case(MessageLayout *layout, const void *storage, const upb_oneofdef *oneof)
VALUE layout_has(MessageLayout *layout, const void *storage, const upb_fielddef *field)
const rb_data_type_t Map_type
uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f)
static ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES absl::base_internal::AtomicHook< StatusPayloadPrinter > storage
const char * upb_fielddef_defaultstr(const upb_fielddef *f, size_t *len)
VALUE get_msgdef_obj(VALUE descriptor_pool, const upb_msgdef *def)
VALUE native_slot_get(upb_fieldtype_t type, VALUE type_class, const void *memory)
const char * upb_fielddef_name(const upb_fielddef *f)
upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f)
grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:19