MCPcopy Create free account
hub / github.com/apache/thrift / rb_thrift_struct_write

Function rb_thrift_struct_write

lib/rb/ext/struct.c:383–421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

381}
382
383static VALUE rb_thrift_struct_write(VALUE self, VALUE protocol) {
384 // call validate
385 rb_funcall(self, validate_method_id, 0);
386
387 // write struct begin
388 default_write_struct_begin(protocol, rb_class_name(CLASS_OF(self)));
389
390 // iterate through all the fields here
391 VALUE struct_fields = STRUCT_FIELDS(self);
392 VALUE sorted_field_ids = rb_funcall(self, sorted_field_ids_method_id, 0);
393
394 int i = 0;
395 for (i=0; i < RARRAY_LEN(sorted_field_ids); i++) {
396 VALUE field_id = rb_ary_entry(sorted_field_ids, i);
397
398 VALUE field_info = rb_hash_aref(struct_fields, field_id);
399
400 VALUE ttype_value = rb_hash_aref(field_info, type_sym);
401 int ttype = FIX2INT(ttype_value);
402 VALUE field_name = rb_hash_aref(field_info, name_sym);
403
404 VALUE field_value = get_field_value(self, field_name);
405
406 if (!NIL_P(field_value)) {
407 default_write_field_begin(protocol, field_name, ttype_value, field_id);
408
409 write_anything(ttype, field_value, protocol, field_info);
410
411 default_write_field_end(protocol);
412 }
413 }
414
415 default_write_field_stop(protocol);
416
417 // write struct end
418 default_write_struct_end(protocol);
419
420 return Qnil;
421}
422
423//-------------------------------------------
424// Reading section

Callers 1

write_anythingFunction · 0.85

Calls 7

get_field_valueFunction · 0.85
write_anythingFunction · 0.85
default_write_field_endFunction · 0.85
default_write_field_stopFunction · 0.85
default_write_struct_endFunction · 0.85

Tested by

no test coverage detected