Package convex.core.data
Class BlobBuilder
java.lang.Object
convex.core.data.BlobBuilder
Similar to Java StringBuilder designed for concatenating multiple small Blobs to produce a larger
Blob.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ABlob
Accumulator Blob, always a canonical Blob with filled chunksprotected long
Total count of bytes in this BlobBuilderprotected byte[]
Accumulator array for up to a single chunk worth of bytes may be appended to, but never mutated below current position to allow safe wrapping in Blobs -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionappend
(byte b) void
append
(byte[] bs) void
append
(byte[] bs, int offset, int length) append
(char c) Append a character to this Blob.Append a CVM character to this Blobvoid
void
append
(ByteBuffer bb) Appends remaining bytes from a ByteBuffer to this BlobBuilderboolean
check
(long limit) Checks if this BlobBuilder is less than or equal to the specified limitvoid
clear()
Clears this BlobBuilder, preparing for new appends to an empty Bloblong
count()
Current number of bytes accumulated in this BlobBuilderslice
(long start, long end) Takes a slice of the Blob currently under construction.toBlob()
Gets a blob representing the current contents of this BlobBuilder.
-
Field Details
-
acc
Accumulator Blob, always a canonical Blob with filled chunks -
tail
protected byte[] tailAccumulator array for up to a single chunk worth of bytes may be appended to, but never mutated below current position to allow safe wrapping in Blobs -
count
protected long countTotal count of bytes in this BlobBuilder
-
-
Constructor Details
-
BlobBuilder
public BlobBuilder() -
BlobBuilder
-
-
Method Details
-
append
-
append
-
toBlob
Gets a blob representing the current contents of this BlobBuilder. O(log n) but quite high overhead, avoid calling too frequently- Returns:
- Blob contents of this BlobBuilder
-
slice
Takes a slice of the Blob currently under construction. May be more efficient than toBLob().slice(...).- Parameters:
start
- Start index of slice (inclusive)end
- End index of slice (exclusive)- Returns:
- Slice of Blob under construction
-
getCVMString
-
count
public long count()Current number of bytes accumulated in this BlobBuilder- Returns:
- Number of bytes
-
append
-
append
-
append
public void append(byte[] bs) -
append
public void append(byte[] bs, int offset, int length) -
append
Append a character to this Blob. Converts to UTF=8- Parameters:
c
- Java character (UTF-16)- Returns:
- This BlobBuilder
-
append
Append a CVM character to this Blob- Parameters:
c
- CVM Character- Returns:
- This BlobBuilder
-
check
public boolean check(long limit) Checks if this BlobBuilder is less than or equal to the specified limit- Parameters:
limit
- Maximum allowable length of BlobBuilder- Returns:
- true if within limit, false if exceeded
-
append
Appends remaining bytes from a ByteBuffer to this BlobBuilder- Parameters:
bb
- ByteBuffer to append
-
clear
public void clear()Clears this BlobBuilder, preparing for new appends to an empty Blob
-