sfml3.rb

Class: SFML::Buffer

Inherits:
Object
  • Object
show all
Defined in:
ext/system/buffer.c,
ext/system/buffer.c

Overview

A raw byte buffer, as used for encoded/decoded audio and image data elsewhere in the library.

Instance Method Summary collapse

Constructor Details

#new ⇒ Buffer

Creates a new, empty byte buffer.

Raises:

  • (NoMemoryError) —

    if the underlying buffer could not be allocated



41
42
43
# File 'ext/system/buffer.c', line 41

static VALUE Buffer_initialize(VALUE self) {
    return self;
}

Instance Method Details

#data ⇒ String

Returns the raw bytes held by the buffer.

Returns:

  • (String)

Returns:

  • (String) —

    the raw bytes, as a binary String



61
62
63
64
65
66
67
68
69
70
71
# File 'ext/system/buffer.c', line 61

static VALUE Buffer_get_data(VALUE self) {
    sfBuffer* buffer = Get_Buffer_Struct(self);
    size_t size = sfBuffer_getSize(buffer);
    const uint8_t* data = sfBuffer_getData(buffer);

    if (data == NULL || size == 0) {
        return rb_str_new("", 0);
    }

    return rb_str_new((const char*)data, (long)size);
}

#empty? ⇒ Boolean

Returns true if the buffer holds no bytes.

Returns:

  • (Boolean)

Returns:

  • (Boolean)


79
80
81
# File 'ext/system/buffer.c', line 79

static VALUE Buffer_is_empty(VALUE self) {
    return BOOL2RB(sfBuffer_getSize(Get_Buffer_Struct(self)) == 0);
}

#size ⇒ Integer

Returns the size of the buffer in bytes.

Returns:

  • (Integer)

Returns:

  • (Integer) —

    size in bytes



51
52
53
# File 'ext/system/buffer.c', line 51

static VALUE Buffer_get_size(VALUE self) {
    return SIZET2NUM(sfBuffer_getSize(Get_Buffer_Struct(self)));
}

#size ⇒ Integer

Returns the size of the buffer in bytes.

Returns:

  • (Integer)

Returns:

  • (Integer) —

    size in bytes



51
52
53
# File 'ext/system/buffer.c', line 51

static VALUE Buffer_get_size(VALUE self) {
    return SIZET2NUM(sfBuffer_getSize(Get_Buffer_Struct(self)));
}

#data ⇒ String

Returns the raw bytes held by the buffer.

Returns:

  • (String)

Returns:

  • (String) —

    the raw bytes, as a binary String



61
62
63
64
65
66
67
68
69
70
71
# File 'ext/system/buffer.c', line 61

static VALUE Buffer_get_data(VALUE self) {
    sfBuffer* buffer = Get_Buffer_Struct(self);
    size_t size = sfBuffer_getSize(buffer);
    const uint8_t* data = sfBuffer_getData(buffer);

    if (data == NULL || size == 0) {
        return rb_str_new("", 0);
    }

    return rb_str_new((const char*)data, (long)size);
}