Package convex.core.data
Class ADerivedBlob
java.lang.Object
- All Implemented Interfaces:
IValidated
,IWriteable
,Comparable<ABlobLike<?>>
- Direct Known Subclasses:
ZeroBlob
Abstract Blob base base for Blobs that derive their functionality from other sources.
Allows extension of ABlob interface to various backing stores.
-
Field Summary
Fields inherited from class convex.core.data.ACell
cachedRef, memorySize
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAppend an additional Blob to this, creating a new Blob as needed.int
encodeRaw
(byte[] bs, int pos) Writes this Blob's encoding to a byte array, excluding the tag byteboolean
Determines if this Blob is equal to another Blob.boolean
equalsBytes
(byte[] bytes, long offset) Tests if the byte contents of this instance are equal to a subset of a byte arrayboolean
equalsBytes
(ABlob b) Tests if this Blob has exactly the same bytes as another Blobint
Estimate the encoded data size for this Cell.Gets a byte buffer containing this Blob's raw data.abstract int
getBytes
(byte[] dest, int destOffset) Copies the bytes from this instance to a given destination arraygetChunk
(long i) Gets a chunk of this Blob, as a canonical flat Blob up to the maximum Blob chunk size.int
Gets the number of Refs contained within this Cell.long
Returns the number of matching hex digits in the given hex range of another Blob.boolean
Returns true if this Cell is in a canonical representation.boolean
Returns true if this is a fully packed set of chunkslong
Converts this BlobLike to the corresponding long value.int
read
(long offset, long count, ByteBuffer dest) Gets bytes from this Blob into a ByteBufferfinal ABlob
slice
(long start, long end) Gets a contiguous slice of this Blob, as a new Blob.protected abstract ABlob
sliceImpl
(long start, long end) Constructs a slice of this Blob as the same type.Converts this Cell to a canonical version.Converts the contents of this value to a flat array-backed Blob instance.protected void
updateDigest
(MessageDigest digest) Methods inherited from class convex.core.data.ABlob
byteAt, compareTo, computeHash, count, empty, encode, equals, get, getContentHash, getElementRef, getTag, getType, hashCode, isChunkPacked, isCVMValue, print, read, replaceSlice, shortAt, size, slice, toBlob, toByteBuffer, validate, validateCell
Methods inherited from class convex.core.data.ABlobLike
appendHex, byteAtUnchecked, getBytes, getHexDigit, hexEquals, hexLength, hexMatch, isDataValue, toHexString, toHexString
Methods inherited from class convex.core.data.ACountable
isEmpty
Methods inherited from class convex.core.data.ACell
attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createEncoding, createRef, equals, genericEquals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getMemorySize, getRef, getRef, isEmbedded, toCVMString, toString, updateRefs
Methods inherited from class convex.core.data.AObject
attachEncoding, print, print
-
Constructor Details
-
ADerivedBlob
protected ADerivedBlob(long count)
-
-
Method Details
-
estimatedEncodingSize
public int estimatedEncodingSize()Description copied from interface:IWriteable
Estimate the encoded data size for this Cell. Used for quickly sizing buffers. Implementations should try to return a size that is highly likely to contain the entire object when encoded, including the tag byte. Should not traverse soft Refs, i.e. must be usable on arbitrary partial data structures- Returns:
- The estimated size for the binary representation of this object.
-
slice
Description copied from class:ABlob
Gets a contiguous slice of this Blob, as a new Blob. Shares underlying backing data where possible -
sliceImpl
Constructs a slice of this Blob as the same type. Assumes a new slice must be constructed and that bounds have already been checked.- Parameters:
start
- Start of sliceend
- End of slice- Returns:
- New slice instance
-
toFlatBlob
Description copied from class:ABlobLike
Converts the contents of this value to a flat array-backed Blob instance. Warning: might be O(n) in size of Blob, may not be canonical etc.- Specified by:
toFlatBlob
in classABlob
- Returns:
- A Blob instance containing the same data as this value. Might be `this` if already a flat Blob.
-
updateDigest
- Specified by:
updateDigest
in classABlob
-
append
-
equals
Description copied from class:ABlob
Determines if this Blob is equal to another Blob. Blobs are defined to be equal if they have the same encoded representation, i.e. if and only if all of the following are true: - Blobs are of the same length - All byte values are equal -
toCanonical
Description copied from class:ACell
Converts this Cell to a canonical version. Must return this Cell if already canonical, may be O(n) in size of value otherwise. Callers should usually use getCanonical(), which caches canonical instances once created- Specified by:
toCanonical
in classABlob
- Returns:
- Canonical version of Cell
-
equalsBytes
public boolean equalsBytes(byte[] bytes, long offset) Description copied from class:ABlob
Tests if the byte contents of this instance are equal to a subset of a byte array- Specified by:
equalsBytes
in classABlob
- Parameters:
bytes
- Byte array to compare withoffset
- Offset into byte array from which to start comparison- Returns:
- true if exactly equal, false otherwise
-
getChunk
Description copied from class:ABlob
Gets a chunk of this Blob, as a canonical flat Blob up to the maximum Blob chunk size. Returns empty Blob if and only if referencing the end of a Blob with fully packed chunks -
getByteBuffer
Description copied from class:ABlob
Gets a byte buffer containing this Blob's raw data. Will have remaining bytes equal to this Blob's size.- Specified by:
getByteBuffer
in classABlob
- Returns:
- A ByteBuffer containing the Blob's data.
-
encodeRaw
public int encodeRaw(byte[] bs, int pos) Description copied from class:ABlob
Writes this Blob's encoding to a byte array, excluding the tag byte -
equalsBytes
Description copied from class:ABlob
Tests if this Blob has exactly the same bytes as another Blob- Specified by:
equalsBytes
in classABlob
- Parameters:
b
- Blob to compare with- Returns:
- True if byte content is exactly equal, false otherwise
-
isFullyPacked
public boolean isFullyPacked()Description copied from class:ABlob
Returns true if this is a fully packed set of chunks- Specified by:
isFullyPacked
in classABlob
- Returns:
- True if fully packed, false otherwise
-
read
Description copied from class:ABlob
Gets bytes from this Blob into a ByteBuffer -
hexMatch
Description copied from class:ABlobLike
Returns the number of matching hex digits in the given hex range of another Blob. Assumes range is valid for both blobs. Returns length if this Blob is exactly equal to the specified hex range. -
getBytes
public abstract int getBytes(byte[] dest, int destOffset) Description copied from class:ABlobLike
Copies the bytes from this instance to a given destination array -
longValue
public long longValue()Description copied from class:ABlobLike
Converts this BlobLike to the corresponding long value. Assumes big-endian format, as if the entire blob is interpreted as an unsigned big integer. Higher bytes outside the Long range will be ignored, i.e. the lowest 64 bits are taken -
isCanonical
public boolean isCanonical()Description copied from class:ACell
Returns true if this Cell is in a canonical representation. Non-canonical objects may be used on a temporary internal basis, they should be converted to canonical representations for general purpose use.- Specified by:
isCanonical
in classACell
- Returns:
- true if the object is in canonical format, false otherwise
-
getRefCount
public int getRefCount()Description copied from class:ACell
Gets the number of Refs contained within this Cell. This number is final / immutable for any given instance and is defined by the Cell encoding rules. Contained Refs may be either external or embedded.- Overrides:
getRefCount
in classACell
- Returns:
- The number of Refs in this Cell
-