Package convex.core.data
Class ABlobLike<T extends ACell>
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.data.ACountable<T>
convex.core.data.ABlobLike<T>
- Type Parameters:
T
- type of conceptual elements
- All Implemented Interfaces:
IValidated
,IWriteable
,Comparable<ABlobLike<?>>
public abstract class ABlobLike<T extends ACell>
extends ACountable<T>
implements Comparable<ABlobLike<?>>
Abstract base class for Blob-like objects, which conceptually behave as a sequence of bytes.
Includes hex-related functionality for printing and usage in radix trees etc.
-
Field Summary
Fields inherited from class convex.core.data.ACell
cachedRef, memorySize
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
appendHex
(BlobBuilder bb, long length) Append hex string up to the given length in hex digits (a multiple of two)abstract byte
byteAt
(long i) Gets the byte at the specified position.byte
byteAtUnchecked
(long i) Gets the byte at the specified position in this data object, possibly skipping bounds checking.abstract int
empty()
Returns a canonical, singleton empty instance of the same type as this Countable value.abstract boolean
equalsBytes
(ABlob b) Compare the byte content of this BlobLike to a Blob valuebyte[]
getBytes()
Gets a new byte array containing a copy of this Blob.abstract int
getBytes
(byte[] dest, int destOffset) Copies the bytes from this instance to a given destination arraygetElementRef
(long index) Gets a Ref to the element at the specified element index in this collectionint
getHexDigit
(long digitPos) Gets the specified hex digit from this data object.boolean
long
Gets the length of this value in hex digitslong
Computes the length of the longest common hex prefix between two blobsabstract long
Returns the number of matching hex digits in the given hex range of another Blob.boolean
Returns true if this cell instance is a first class value, i.e.abstract long
Converts this BlobLike to the corresponding long value.abstract ABlob
toBlob()
Convert this BlobLike object to an ABlob instance, in the most efficient way.Converts the contents of this value to a flat array-backed Blob instance.Converts this data object to a lowercase hex string representationfinal String
toHexString
(int hexLength) Converts this data object to a hex string representation of the given length.Methods inherited from class convex.core.data.ACell
attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createEncoding, createRef, encode, encodeRaw, equals, equals, genericEquals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getMemorySize, getRef, getRef, getRefCount, getTag, getType, hashCode, isCanonical, isCVMValue, isEmbedded, toCanonical, toCVMString, toString, updateRefs, validate, validateCell
Methods inherited from class convex.core.data.AObject
attachEncoding, print, print, print
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface convex.core.data.IWriteable
estimatedEncodingSize
-
Constructor Details
-
ABlobLike
public ABlobLike()
-
-
Method Details
-
byteAt
public abstract byte byteAt(long i) Gets the byte at the specified position. Result is undefined if out of range.- Parameters:
i
- Index of the byte to get- Returns:
- The byte at the specified position
-
byteAtUnchecked
public byte byteAtUnchecked(long i) Gets the byte at the specified position in this data object, possibly skipping bounds checking. Only safe if index is known to be in bounds, otherwise result is undefined.- Parameters:
i
- Index of the byte to get- Returns:
- The byte at the specified position
-
getHexDigit
public int getHexDigit(long digitPos) Gets the specified hex digit from this data object. WARNING: Result is undefined if index is out of bounds, but probably an IndexOutOfBoundsException.- Parameters:
digitPos
- The position of the hex digit- Returns:
- The value of the hex digit, in the range 0-15 inclusive
-
hexMatch
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.- Parameters:
b
- Blob to compare withstart
- Start position (in hex digits)length
- Length to compare (in hex digits)- Returns:
- The number of matching hex characters
-
hexMatch
Computes the length of the longest common hex prefix between two blobs- Parameters:
b
- Blob to compare with- Returns:
- The length of the longest common prefix in hex digits
-
hexEquals
-
empty
Description copied from class:ACountable
Returns a canonical, singleton empty instance of the same type as this Countable value.- Specified by:
empty
in classACountable<T extends ACell>
- Returns:
- An empty Countable value, or null if there is no empty instance
-
getBytes
public byte[] getBytes()Gets a new byte array containing a copy of this Blob.- Returns:
- A new byte array containing the contents of this blob.
-
getElementRef
Description copied from class:ACountable
Gets a Ref to the element at the specified element index in this collection- Specified by:
getElementRef
in classACountable<T extends ACell>
- Parameters:
index
- Index of element to get- Returns:
- Element at the specified index
-
getBytes
public abstract int getBytes(byte[] dest, int destOffset) Copies the bytes from this instance to a given destination array- Parameters:
dest
- Destination arraydestOffset
- Offset into destination array- Returns:
- End position in destination array after writing
-
hexLength
public long hexLength()Gets the length of this value in hex digits- Returns:
- Number of hex digits
-
toHexString
Converts this data object to a hex string representation of the given length. Equivalent to truncating the full String representation.- Parameters:
hexLength
- Length to truncate String to (in hex characters)- Returns:
- String representation of hex values in Blob
-
toHexString
Converts this data object to a lowercase hex string representation- Returns:
- Hex String representation
-
appendHex
Append hex string up to the given length in hex digits (a multiple of two)- Parameters:
bb
- BlobBuilder instance to append tolength
- Length in Hex digits to append- Returns:
- true if Blob fully appended, false if more more hex digits remain
-
longValue
public abstract long longValue()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- Returns:
- long value of this blob
-
toBlob
Convert this BlobLike object to an ABlob instance, in the most efficient way. May return `this`.- Returns:
- Blob instance
-
toFlatBlob
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.- Returns:
- A Blob instance containing the same data as this value. Might be `this` if already a flat Blob.
-
equalsBytes
Compare the byte content of this BlobLike to a Blob value- Parameters:
b
- Blob value to compare with- Returns:
- `true` if byte contents are exactly equal, `false` otherwise
-
compareTo
- Specified by:
compareTo
in interfaceComparable<T extends ACell>
-
isDataValue
public boolean isDataValue()Description copied from class:ACell
Returns true if this cell instance is a first class value, i.e. not a component of a larger data structure Sub-structural cells that are not themselves first class values should return false Everything else should return true.- Specified by:
isDataValue
in classACell
- Returns:
- true if the object is a Value, false otherwise
-