CBuffer[optional A: Integer[A] val]¶
Constructors¶
create¶
Allocate a buffer of size bytes, zero-filled. CBuffer explicitly
does not support resize. To grow, construct a new CBuffer and copy.
The type parameter A selects the numeric type backing written_size.
It defaults to ISize so the negative-sentinel idiom remains available;
callers wanting an unsigned width (e.g. CBuffer[U32]) can override.
Parameters¶
Returns¶
- CBuffer[A] ref^
Public Functions¶
allocated¶
Returns allocated capacity in bytes.
Returns¶
- USize val
reset¶
Zero-fill the buffer and reset written_size to 0.
Returns¶
- None val
ptr¶
Base pointer for FFI calls.
Returns¶
get_written_size¶
Most recent filled length, in bytes. When A is signed, callers may
use negative values as out-of-band sentinels.
Returns¶
- A
set_written_size¶
Set written_size from Pony code. Useful when a caller wants to mark
the buffer with a sentinel without going through C.
Parameters¶
- n: A
Returns¶
- None val
written_size_ptr¶
Address of the written_size field, for C functions that report the
filled length through an out-parameter.
Returns¶
- CBox[A] ref
write¶
Copy str into the buffer and set written_size to its length. Returns
false (leaving the buffer unchanged) if str exceeds capacity.
Refuses truncation rather than silently dropping bytes.
bzero can be disabled for performance reasons if dealing with massive allocations in hot-paths. You probably shouldn't unless you're certain you know what you're doing.
Parameters¶
Returns¶
- Bool val
write_array¶
Copy arr into the buffer and set written_size to its length. Returns
false (leaving the buffer unchanged) if the buffer is not allocated or
arr exceeds capacity.
Refuses truncation rather than silently dropping bytes.
bzero can be disabled for performance reasons if dealing with massive allocations in hot-paths. You probably shouldn't unless you're certain you know what you're doing.
Parameters¶
Returns¶
- Bool val
copy_string_truncated¶
Copy the filled region out as a String. Errors if the buffer is not
allocated or written_size is negative. If written_size exceeds
cap() (e.g. a C caller reporting truncation), the result is clamped
to cap() rather than walking off the end of the allocation.
Returns¶
- String iso^ ?
copy_array_truncated¶
Copy the filled region out as an Array[U8]. Same error and clamp
semantics as copy_string_truncated().
Returns¶
copy_string¶
Copy the filled region out as a String. Errors if the buffer is not
allocated or written_size is negative, or if written_size is greater
than the allocated space.
Returns¶
- String iso^ ?
copy_array¶
Copy the filled region out as an Array[U8]. Same error semantics as
copy_string().