Go to the documentation of this file.
38 "Google::Protobuf::RepeatedField",
51 return ((uint8_t *)
self->elements) +
index * element_size;
55 int index = NUM2INT(_index);
68 size_t off = beg * element_size;
69 VALUE ary = rb_ary_new2(
len);
70 for (
int i = beg;
i < beg +
len;
i++, off += element_size) {
71 void* mem = ((uint8_t *)
self->elements) + off;
73 rb_ary_push(ary, elem);
93 for (
int i = 0;
i <
self->size;
i++, off += element_size) {
94 void* memory = (
void *) (((uint8_t *)
self->elements) + off);
129 switch (rb_range_beg_len(arg, &beg, &
len,
self->size, 0)) {
140 beg = NUM2LONG(argv[0]);
141 len = NUM2LONG(argv[1]);
145 if (beg >=
self->size) {
177 self->size =
index + 1;
188 void* old_elems =
self->elements;
190 if (new_size <= self->capacity) {
193 if (
self->capacity == 0) {
196 while (
self->capacity < new_size) {
199 self->elements =
ALLOC_N(uint8_t, elem_size *
self->capacity);
200 if (old_elems !=
NULL) {
201 memcpy(
self->elements, old_elems,
self->size * elem_size);
219 memory = (
void *) (((uint8_t *)
self->elements) +
self->size * element_size);
227 for (
int i = 0;
i < RARRAY_LEN(
args);
i++) {
241 memory = (
void *) (((uint8_t *)
self->elements) +
self->size * element_size);
242 memcpy(memory,
data, element_size);
270 if (
self->size == 0) {
273 index =
self->size - 1;
288 Check_Type(list, T_ARRAY);
290 for (
int i = 0;
i < RARRAY_LEN(list);
i++) {
316 return INT2NUM(
self->size);
321 VALUE new_rptfield = Qnil;
323 if (
self->field_type_class != Qnil) {
324 new_rptfield = rb_funcall(CLASS_OF(_self), rb_intern(
"new"), 2,
325 element_type,
self->field_type_class);
327 new_rptfield = rb_funcall(CLASS_OF(_self), rb_intern(
"new"), 1,
348 for (
int i = 0;
i <
self->size;
i++, off += elem_size) {
349 void* to_mem = (uint8_t *)new_rptfield_self->
elements + off;
350 void* from_mem = (uint8_t *)
self->elements + off;
352 new_rptfield_self->
size++;
367 for (
int i = 0;
i <
self->size;
i++, off += elem_size) {
368 void* to_mem = (uint8_t *)new_rptfield_self->
elements + off;
369 void* from_mem = (uint8_t *)
self->elements + off;
371 new_rptfield_self->
size++;
390 VALUE ary = rb_ary_new2(
self->size);
391 for (
int i = 0;
i <
self->size;
i++, off += elem_size) {
392 void* mem = ((uint8_t *)
self->elements) + off;
394 rb_ary_push(ary, elem);
416 if (_self == _other) {
420 if (
TYPE(_other) == T_ARRAY) {
422 return rb_equal(self_ary, _other);
437 for (
int i = 0;
i <
self->size;
i++, off += elem_size) {
438 void* self_mem = ((uint8_t *)
self->elements) + off;
439 void* other_mem = ((uint8_t *)other->
elements) + off;
456 st_index_t
h = rb_hash_start(0);
457 VALUE hash_sym = rb_intern(
"hash");
462 for (
int i = 0;
i <
self->size;
i++, off += elem_size) {
463 void* mem = ((uint8_t *)
self->elements) + off;
465 h = rb_hash_uint(
h, NUM2LONG(rb_funcall(elem, hash_sym, 0)));
483 if (
TYPE(list) == T_ARRAY) {
484 for (
int i = 0;
i < RARRAY_LEN(list);
i++) {
485 VALUE elem = rb_ary_entry(list,
i);
488 }
else if (RB_TYPE_P(list, T_DATA) && RTYPEDDATA_P(list) &&
494 rb_raise(rb_eArgError,
495 "Attempt to append RepeatedField with different element type.");
497 for (
int i = 0;
i < list_rptfield->
size;
i++) {
502 rb_raise(rb_eArgError,
"Unknown type appending to RepeatedField");
515 Check_Type(list, T_ARRAY);
516 for (
int i = 0;
i < RARRAY_LEN(list);
i++) {
525 rb_raise(rb_eArgError,
526 "Type class has no descriptor. Please pass a "
527 "class or enum as returned by the DescriptorPool.");
531 if (!RB_TYPE_P(
desc, T_DATA) || !RTYPEDDATA_P(
desc) ||
533 rb_raise(rb_eArgError,
"Descriptor has an incorrect type.");
536 rb_raise(rb_eArgError,
537 "Message class was not returned by the DescriptorPool.");
541 if (!RB_TYPE_P(enumdesc, T_DATA) || !RTYPEDDATA_P(enumdesc) ||
543 rb_raise(rb_eArgError,
"Descriptor has an incorrect type.");
553 rb_raise(rb_eArgError,
"Expected at least 1 argument.");
560 rb_raise(rb_eArgError,
"Expected at least 2 arguments for message/enum.");
562 self->field_type_class = argv[1];
569 rb_raise(rb_eArgError,
"Too many arguments: expected 1 or 2.");
577 if (!RB_TYPE_P(ary, T_ARRAY)) {
578 rb_raise(rb_eArgError,
"Expected array as initialize argument");
580 for (
int i = 0;
i < RARRAY_LEN(ary);
i++) {
592 rb_gc_mark(
self->field_type_class);
593 for (
int i = 0;
i <
self->size;
i++) {
594 void* memory = (((uint8_t *)
self->elements) +
i * element_size);
601 xfree(
self->elements);
618 self->elements =
NULL;
621 self->field_type = -1;
622 self->field_type_class = Qnil;
632 VALUE
klass = rb_define_class_under(
633 module,
"RepeatedField", rb_cObject);
638 rb_define_method(
klass,
"initialize",
659 rb_include_module(
klass, rb_mEnumerable);
void native_slot_dup(upb_fieldtype_t type, void *to, void *from)
VALUE RepeatedField_concat(VALUE _self, VALUE list)
bool native_slot_set(upb_fieldtype_t type, const zend_class_entry *klass, void *memory, zval *value TSRMLS_DC)
int RepeatedField_size(VALUE _self)
zend_class_entry * field_type
void native_slot_init(upb_fieldtype_t type, void *memory, CACHED_VALUE *cache)
void RepeatedField_reserve(RepeatedField *self, int new_size)
ID descriptor_instancevar_interned
const rb_data_type_t _EnumDescriptor_type
PHP_PROTO_OBJECT_FREE_END PHP_PROTO_OBJECT_DTOR_END intern self
void RepeatedField_init_args(int argc, VALUE *argv, VALUE _self)
VALUE RepeatedField_subarray(VALUE _self, long beg, long len)
static VALUE RepeatedField_new_this_type(VALUE _self)
void validate_type_class(upb_fieldtype_t type, VALUE klass)
VALUE RepeatedField_replace(VALUE _self, VALUE list)
VALUE RepeatedField_index_set(VALUE _self, VALUE _index, VALUE val)
upb_fieldtype_t field_type
VALUE RepeatedField_plus(VALUE _self, VALUE list)
size_t native_slot_size(upb_fieldtype_t type)
VALUE Message_alloc(VALUE klass)
bool native_slot_eq(upb_fieldtype_t type, void *mem1, void *mem2)
VALUE RepeatedField_init(int argc, VALUE *argv, VALUE self)
VALUE RepeatedField_each(VALUE _self)
void * RepeatedField_index_native(VALUE _self, int index)
#define ALLOC(class_name)
VALUE RepeatedField_push_vararg(VALUE _self, VALUE args)
const rb_data_type_t _Descriptor_type
PHP_PROTO_OBJECT_FREE_END PHP_PROTO_OBJECT_DTOR_END intern repeated_field
VALUE RepeatedField_length(VALUE _self)
#define ALLOC_N(class_name, n)
void native_slot_mark(upb_fieldtype_t type, void *memory)
const rb_data_type_t RepeatedField_type
RepeatedField * ruby_to_RepeatedField(VALUE _self)
const zend_class_entry * field_type_class(const upb_fielddef *field PHP_PROTO_TSRMLS_DC)
VALUE RepeatedField_push(VALUE _self, VALUE val)
static int index_position(VALUE _index, RepeatedField *repeated_field)
void RepeatedField_register(VALUE module)
void native_slot_deep_copy(upb_fieldtype_t type, void *to, void *from)
void RepeatedField_mark(void *_self)
void native_slot_get(upb_fieldtype_t type, const void *memory, CACHED_VALUE *cache TSRMLS_DC)
void RepeatedField_push_native(VALUE _self, void *data)
VALUE RepeatedField_dup(VALUE _self)
VALUE RepeatedField_alloc(VALUE klass)
VALUE RepeatedField_deep_copy(VALUE _self)
VALUE fieldtype_to_ruby(upb_fieldtype_t type)
VALUE RepeatedField_clear(VALUE _self)
VALUE RepeatedField_hash(VALUE _self)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
VALUE RepeatedField_index(int argc, VALUE *argv, VALUE _self)
VALUE RepeatedField_pop_one(VALUE _self)
upb_fieldtype_t ruby_to_fieldtype(VALUE type)
void RepeatedField_free(void *_self)
void * RepeatedField_memoryat(RepeatedField *self, int index, int element_size)
GLfloat GLfloat GLfloat GLfloat h
VALUE RepeatedField_eq(VALUE _self, VALUE _other)
VALUE RepeatedField_to_ary(VALUE _self)
libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:58