Class: Plamo::ByteArray

Inherits:
Object
  • Object
show all
Defined in:
ext/plamo/plamo_byte_array.c

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Object



25
26
27
28
# File 'ext/plamo/plamo_byte_array.c', line 25

static VALUE initialize(VALUE self, VALUE body) {
  DATA_PTR(self) = plamo_byte_array_new((const unsigned char*)RARRAY_PTR(body), RARRAY_LEN(body));
  return self;
}

Instance Method Details

#bodyObject



30
31
32
33
34
35
36
37
38
39
40
# File 'ext/plamo/plamo_byte_array.c', line 30

static VALUE get_body(VALUE self) {
  PlamoByteArray *plamo_byte_array;
  TypedData_Get_Struct(self, PlamoByteArray, &rb_plamo_byte_array_type, plamo_byte_array);
  const size_t size = plamo_byte_array_get_body_size(plamo_byte_array);
  const unsigned char *body = plamo_byte_array_get_body(plamo_byte_array);
  VALUE rb_array = rb_ary_new2(size);
  for (int i = 0; i < size; i++) {
    rb_ary_store(rb_array, i, CHR2FIX(*(body + i)));
  }
  return rb_array;
}

#sizeObject



42
43
44
45
46
# File 'ext/plamo/plamo_byte_array.c', line 42

static VALUE get_size(VALUE self) {
  PlamoByteArray *plamo_byte_array;
  TypedData_Get_Struct(self, PlamoByteArray, &rb_plamo_byte_array_type, plamo_byte_array);
  return ULONG2NUM(plamo_byte_array_get_body_size(plamo_byte_array));
}