Go to the documentation of this file.
65 #define TABLE_KEY_BUF_LENGTH 8 // sizeof(uint64_t)
70 switch (
self->key_type) {
74 Check_Type(
key, T_STRING);
76 *out_key = RSTRING_PTR(
key);
77 *out_length = RSTRING_LEN(
key);
101 switch (
self->key_type) {
105 rb_enc_associate(ret,
125 return (
void*)(&
v->val);
133 "Google::Protobuf::Map",
148 rb_gc_mark(
self->value_type_class);
149 rb_gc_mark(
self->parse_frame);
173 memset(
self, 0,
sizeof(
Map));
174 self->value_type_class = Qnil;
180 self->parse_frame =
val;
224 VALUE
Map_init(
int argc, VALUE* argv, VALUE _self) {
231 if (argc < 2 || argc > 4) {
232 rb_raise(rb_eArgError,
"Map constructor expects 2, 3 or 4 arguments.");
237 self->parse_frame = Qnil;
240 switch (
self->key_type) {
251 rb_raise(rb_eArgError,
"Invalid key type for map.");
256 self->value_type_class = argv[2];
264 rb_raise(rb_eRuntimeError,
"Could not allocate table.");
267 if (argc > init_value_arg) {
296 self->value_type_class,
314 VALUE ret = rb_ary_new();
323 rb_ary_push(ret,
key);
338 VALUE ret = rb_ary_new();
347 self->value_type_class,
350 rb_ary_push(ret,
value);
367 const char* keyval =
NULL;
389 rb_check_frozen(_self);
394 const char* keyval =
NULL;
406 rb_raise(rb_eRuntimeError,
"Could not insert into table");
424 const char* keyval =
NULL;
443 rb_check_frozen(_self);
448 const char* keyval =
NULL;
468 rb_check_frozen(_self);
476 rb_raise(rb_eRuntimeError,
"Unable to re-initialize table");
494 VALUE new_map = Qnil;
497 if (
self->value_type_class != Qnil) {
498 new_map = rb_funcall(CLASS_OF(_self), rb_intern(
"new"), 3,
501 new_map = rb_funcall(CLASS_OF(_self), rb_intern(
"new"), 2,
534 rb_raise(rb_eRuntimeError,
"Error inserting value into new table");
562 rb_raise(rb_eRuntimeError,
"Error inserting value into new table");
582 VALUE
Map_eq(VALUE _self, VALUE _other) {
589 if (
TYPE(_other) == T_HASH) {
646 st_index_t
h = rb_hash_start(0);
647 VALUE hash_sym = rb_intern(
"hash");
659 self->value_type_class,
662 h = rb_hash_uint(
h, NUM2LONG(rb_funcall(
key, hash_sym, 0)));
663 h = rb_hash_uint(
h, NUM2LONG(rb_funcall(
value, hash_sym, 0)));
677 VALUE hash = rb_hash_new();
687 self->value_type_class,
709 VALUE
str = rb_str_new2(
"{");
712 VALUE inspect_sym = rb_intern(
"inspect");
724 self->value_type_class,
728 str = rb_str_cat2(
str,
", ");
732 str = rb_str_append(
str, rb_funcall(
key, inspect_sym, 0));
733 str = rb_str_cat2(
str,
"=>");
734 str = rb_str_append(
str, rb_funcall(
value, inspect_sym, 0));
737 str = rb_str_cat2(
str,
"}");
762 if (
TYPE(hashmap) == T_HASH) {
764 }
else if (RB_TYPE_P(hashmap, T_DATA) && RTYPEDDATA_P(hashmap) &&
765 RTYPEDDATA_TYPE(hashmap) == &
Map_type) {
774 rb_raise(rb_eArgError,
"Attempt to merge Map with mismatching types");
796 rb_raise(rb_eArgError,
"Unknown type merging into Map");
832 VALUE
klass = rb_define_class_under(module,
"Map", rb_cObject);
834 rb_gc_register_address(&
cMap);
853 rb_include_module(
klass, rb_mEnumerable);
void native_slot_dup(upb_fieldtype_t type, void *to, void *from)
VALUE Map_inspect(VALUE _self)
bool native_slot_set(upb_fieldtype_t type, const zend_class_entry *klass, void *memory, zval *value TSRMLS_DC)
VALUE Map_merge(VALUE _self, VALUE hashmap)
static void * value_memory(upb_value *v)
VALUE Map_values(VALUE _self)
VALUE Map_delete(VALUE _self, VALUE key)
size_t upb_strtable_iter_keylength(const upb_strtable_iter *i)
GLenum GLuint GLenum GLsizei length
VALUE Message_to_h(VALUE _self)
static VALUE table_key_to_ruby(Map *self, const char *buf, size_t length)
VALUE Map_merge_into_self(VALUE _self, VALUE hashmap)
VALUE Map_dup(VALUE _self)
PHP_PROTO_OBJECT_FREE_END PHP_PROTO_OBJECT_DTOR_END intern self
VALUE Map_clear(VALUE _self)
bool Map_done(Map_iter *iter)
void validate_type_class(upb_fieldtype_t type, VALUE klass)
UPB_INLINE bool upb_strtable_init(upb_strtable *table, upb_ctype_t ctype)
size_t native_slot_size(upb_fieldtype_t type)
#define TABLE_KEY_BUF_LENGTH
bool native_slot_eq(upb_fieldtype_t type, void *mem1, void *mem2)
Map * ruby_to_Map(VALUE _self)
#define ALLOC(class_name)
static int merge_into_self_callback(VALUE key, VALUE value, VALUE self)
void Map_mark(void *_self)
void upb_strtable_next(upb_strtable_iter *i)
VALUE Map_each(VALUE _self)
static bool needs_typeclass(upb_fieldtype_t type)
VALUE Map_index(VALUE _self, VALUE key)
bool upb_strtable_done(const upb_strtable_iter *i)
const char * upb_strtable_iter_key(const upb_strtable_iter *i)
void Map_next(Map_iter *iter)
VALUE Map_keys(VALUE _self)
rb_encoding * kRubyStringUtf8Encoding
void native_slot_mark(upb_fieldtype_t type, void *memory)
upb_value upb_strtable_iter_value(const upb_strtable_iter *i)
UPB_INLINE void upb_strtable_uninit(upb_strtable *table)
void native_slot_deep_copy(upb_fieldtype_t type, void *to, void *from)
rb_encoding * kRubyString8bitEncoding
void native_slot_get(upb_fieldtype_t type, const void *memory, CACHED_VALUE *cache TSRMLS_DC)
void Map_begin(VALUE _self, Map_iter *iter)
GLenum GLuint GLenum GLsizei const GLchar * buf
const SETUP_TEARDOWN_TESTCONTEXT char * key
VALUE Map_eq(VALUE _self, VALUE _other)
VALUE Map_hash(VALUE _self)
VALUE Map_length(VALUE _self)
void Map_register(VALUE module)
VALUE Map_init(int argc, VALUE *argv, VALUE _self)
VALUE Map_alloc(VALUE klass)
UPB_INLINE bool upb_strtable_insert2(upb_strtable *t, const char *key, size_t len, upb_value val)
static VALUE table_key(Map *self, VALUE key, char *buf, const char **out_key, size_t *out_length)
VALUE Map_index_set(VALUE _self, VALUE key, VALUE value)
VALUE Map_set_frame(VALUE map, VALUE val)
VALUE fieldtype_to_ruby(upb_fieldtype_t type)
zend_class_entry * value_type
VALUE native_slot_encode_and_freeze_string(upb_fieldtype_t type, VALUE value)
void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t)
VALUE Map_to_h(VALUE _self)
VALUE Map_has_key(VALUE _self, VALUE key)
VALUE Map_iter_value(Map_iter *iter)
const rb_data_type_t Map_type
GLsizei const GLfloat * value
void Map_free(void *_self)
bool upb_strtable_lookup2(const upb_strtable *t, const char *key, size_t len, upb_value *v)
upb_fieldtype_t ruby_to_fieldtype(VALUE type)
upb_fieldtype_t value_type
static VALUE Map_new_this_type(VALUE _self)
UPB_INLINE size_t upb_strtable_count(const upb_strtable *t)
VALUE Map_iter_key(Map_iter *iter)
UPB_INLINE bool upb_strtable_remove2(upb_strtable *t, const char *key, size_t len, upb_value *val)
GLfloat GLfloat GLfloat GLfloat h
VALUE Map_deep_copy(VALUE _self)
libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:55