BlobArrayBuilder

class dsviper.BlobArrayBuilder(blob_layout, count)

Bases: object

Fills the bytes of one typed array, then seals them into a ValueBlob.

Write through the buffer protocol, by index, or with copy(); build() hands the bytes over once. A blob’s bytes never change afterwards.

It is constructed in ELEMENTS and indexed in DATA, which are the same number only when an element packs one datum. An index, len() and data_count() all walk the data; count() answers the elements the constructor was given, which is data_count() divided by blob_layout.components(), and byte_count() is data_count() times the data type’s width. So for i in range(count()) fills the first fraction of the array and leaves the rest zero, without raising - range(data_count()) is the loop that fills it.

Two ways to fill it from NumPy, and the difference matters: copy(buffer) writes the whole array in one call and exports nothing, while numpy.asarray(builder) hands out a WRITABLE view for in-place work - which build() then refuses until that view is released, since bytes someone still holds could change after the blob was sealed on them. Either way the dtype follows blob_layout.data_type with nothing to declare.

blob_layout() → BlobLayout

Return the BlobLayout of one element: its data type and how many components it packs.

build() → ValueBlob

Return the ValueBlob of the bytes written so far, and empty the builder.

The bytes are moved, not copied, so a value never shares them with a writer: every later write is refused. Fails while a buffer of this builder is still exported - release the memoryview, or delete the NumPy array holding it, first.

byte_count() → int

Return how many bytes the array occupies: data_count() times blob_layout.data_type_byte_count().

copy(buffer: Buffer) → None

Write buffer over the whole array: byte_count() bytes, which is a sequence of data_count() items of the layout data type, not count().

count() → int

Return how many elements the array holds, fixed at construction.

This is NOT the range an index walks: an element packs blob_layout.components() data, and an index addresses one datum. Loop over data_count(), which is what len() answers.

data_count() → int

Return how many data the array holds: count() times blob_layout.components().

The range an index walks, and what len() answers.

is_built() → bool

Return whether build() has handed the bytes over to a blob.