Project Lucy has retired. For details please refer to its Attic page.
Clownfish::ByteBuf – C API Documentation
Apache Lucy™

Clownfish::ByteBuf

parcel Clownfish
class variable CFISH_BYTEBUF
struct symbol cfish_ByteBuf
class nickname cfish_BB
header file Clownfish/ByteBuf.h

Name

Clownfish::ByteBuf – Growable buffer holding arbitrary bytes.

Functions

new
cfish_ByteBuf* // incremented
cfish_BB_new(
    size_t capacity
);

Return a new zero-sized ByteBuf.

capacity

Initial minimum capacity of the ByteBuf, in bytes.

init
cfish_ByteBuf*
cfish_BB_init(
    cfish_ByteBuf *self,
    size_t capacity
);

Initialize a ByteBuf.

capacity

Initial minimum capacity of the ByteBuf, in bytes.

new_bytes
cfish_ByteBuf* // incremented
cfish_BB_new_bytes(
    void *bytes,
    size_t size
);

Return a new ByteBuf which holds a copy of the passed-in bytes.

bytes

Pointer to an array of bytes.

size

Size of the array in bytes.

init_bytes
cfish_ByteBuf*
cfish_BB_init_bytes(
    cfish_ByteBuf *self,
    void *bytes,
    size_t size
);

Initialize a ByteBuf which holds a copy of the passed-in bytes.

bytes

Pointer to an array of bytes.

size

Size of the array in bytes.

new_steal_bytes
cfish_ByteBuf* // incremented
cfish_BB_new_steal_bytes(
    void *bytes,
    size_t size,
    size_t capacity
);

Return a new ByteBuf which assumes ownership of the passed-in string.

bytes

Pointer to an array of bytes.

size

Initial size of the ByteBuf in bytes.

capacity

Total allocated bytes in the array.

init_steal_bytes
cfish_ByteBuf*
cfish_BB_init_steal_bytes(
    cfish_ByteBuf *self,
    void *bytes,
    size_t size,
    size_t capacity
);

Initialize a ByteBuf and assume ownership of the passed-in string.

bytes

Pointer to an array of bytes.

size

Initial size of the ByteBuf in bytes.

capacity

Total allocated bytes in the array.

Methods

Set_Size
void
cfish_BB_Set_Size(
    cfish_ByteBuf *self,
    size_t size
);

Resize the ByteBuf to size. If greater than the object’s capacity, throws an error.

Get_Size
size_t
cfish_BB_Get_Size(
    cfish_ByteBuf *self
);

Return the size of the ByteBuf in bytes.

Get_Buf
char*
cfish_BB_Get_Buf(
    cfish_ByteBuf *self
);

Accessor for raw internal buffer.

Get_Capacity
size_t
cfish_BB_Get_Capacity(
    cfish_ByteBuf *self
);

Return the number of bytes in the ByteBuf’s allocation.

Cat_Bytes
void
cfish_BB_Cat_Bytes(
    cfish_ByteBuf *self,
    void *bytes,
    size_t size
);

Concatenate the passed-in bytes onto the end of the ByteBuf. Allocate more memory as needed.

bytes

Pointer to an array of bytes.

size

Size of the array in bytes.

Cat
void
cfish_BB_Cat(
    cfish_ByteBuf *self,
    cfish_Blob *blob
);

Concatenate the contents of Blob blob onto the end of the original ByteBuf. Allocate more memory as needed.

Grow
char*
cfish_BB_Grow(
    cfish_ByteBuf *self,
    size_t capacity
);

Assign more memory to the ByteBuf, if it doesn’t already have enough room to hold capacity bytes. Cannot shrink the allocation.

capacity

The new minimum capacity of the ByteBuf.

Returns: a pointer to the raw buffer.

Yield_Blob
cfish_Blob* // incremented
cfish_BB_Yield_Blob(
    cfish_ByteBuf *self
);

Return the content of the ByteBuf as Blob and clear the ByteBuf.

Utf8_To_String
cfish_String* // incremented
cfish_BB_Utf8_To_String(
    cfish_ByteBuf *self
);

Return a String which holds a copy of the UTF-8 character data in the ByteBuf after checking for validity.

Trusted_Utf8_To_String
cfish_String* // incremented
cfish_BB_Trusted_Utf8_To_String(
    cfish_ByteBuf *self
);

Return a String which holds a copy of the UTF-8 character data in the ByteBuf, skipping validity checks.

Equals
bool
cfish_BB_Equals(
    cfish_ByteBuf *self,
    cfish_Obj *other
);

Equality test.

Returns: true if other is a ByteBuf with the same content as self.

Equals_Bytes
bool
cfish_BB_Equals_Bytes(
    cfish_ByteBuf *self,
    void *bytes,
    size_t size
);

Test whether the ByteBuf matches the passed-in bytes.

bytes

Pointer to an array of bytes.

size

Size of the array in bytes.

Compare_To
int32_t
cfish_BB_Compare_To(
    cfish_ByteBuf *self,
    cfish_Obj *other
);

Indicate whether one ByteBuf is less than, equal to, or greater than another. The byte contents of the ByteBufs are compared lexicographically. Throws an exception if other is not a ByteBuf.

Returns: 0 if the ByteBufs are equal, a negative number if self is less than other, and a positive number if self is greater than other.

Clone
cfish_ByteBuf* // incremented
cfish_BB_Clone(
    cfish_ByteBuf *self
);

Return a clone of the object.

Inheritance

Clownfish::ByteBuf is a Clownfish::Obj.