Skip to main content

CopyDataBuilder

Struct CopyDataBuilder 

Source
pub struct CopyDataBuilder { /* private fields */ }
Expand description

A builder for HyperBinary COPY data.

Provides a convenient interface for constructing HyperBinary COPY format data. Automatically writes the header before the first data value.

§Example

use hyperdb_api_core::protocol::copy::CopyDataBuilder;

let mut builder = CopyDataBuilder::new(1024);
builder.write_i32(42, false);
builder.write_str("hello", false);
let data = builder.take();

Implementations§

Source§

impl CopyDataBuilder

Source

pub fn new(capacity: usize) -> Self

Creates a new builder with the specified initial capacity.

§Arguments
  • capacity - Initial buffer capacity in bytes
Source

pub fn with_default_capacity() -> Self

Creates a new builder with default capacity (1 MB).

Source

pub fn ensure_header(&mut self)

Ensures the HyperBinary COPY header is written.

Called automatically before writing any data. Writes the header only once, even if called multiple times.

Source

pub fn write_null(&mut self)

Writes a NULL value.

Source

pub fn write_bool(&mut self, value: bool, nullable: bool)

Writes a boolean value.

Source

pub fn write_i16(&mut self, value: i16, nullable: bool)

Writes an i16 value.

Source

pub fn write_i32(&mut self, value: i32, nullable: bool)

Writes an i32 value.

Source

pub fn write_i64(&mut self, value: i64, nullable: bool)

Writes an i64 value.

Source

pub fn write_data128(&mut self, value: &[u8; 16], nullable: bool)

Writes a 128-bit value.

Source

pub fn write_varbinary(&mut self, value: &[u8], nullable: bool)

Writes a variable-length binary value (text, bytea, etc.).

Source

pub fn write_str(&mut self, value: &str, nullable: bool)

Writes a string value.

Source

pub fn len(&self) -> usize

Returns the current buffer size in bytes.

Includes the header if it has been written.

Source

pub fn is_empty(&self) -> bool

Returns true if the buffer is empty (no data written yet).

Note: This returns true even if the header has been written, since the header is written automatically before data.

Source

pub fn take(&mut self) -> BytesMut

Returns the buffer contents and resets the builder.

The builder can be reused after calling this method. The header flag is reset, so the header will be written again on the next write operation.

Source

pub fn as_bytes(&self) -> &[u8]

Returns a reference to the buffer contents.

Useful for inspecting the data without consuming it.

Source

pub fn clear(&mut self)

Clears the buffer and resets the header flag.

The builder can be reused after clearing. The capacity is preserved.

Trait Implementations§

Source§

impl Debug for CopyDataBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CopyDataBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more