Package convex.core.data
Class AArrayBlob
java.lang.Object
- All Implemented Interfaces:
IValidated
,IWriteable
,Comparable<ABlobLike<?>>
- Direct Known Subclasses:
AccountKey
,ASignature
,Blob
,Hash
Abstract base class for binary data stored in Java arrays.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Hash
Cached hash of the Blob data.protected final int
protected final byte[]
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.final boolean
appendHex
(BlobBuilder bb, long hexLength) Append hex string up to the given length in hex digits (a multiple of two)protected ABlob
appendSmall
(ABlob d) final byte
byteAt
(long i) Gets the byte at the specified positionfinal byte
byteAtUnchecked
(long i) Gets the byte at the specified position in this data object, possibly skipping bounds checking.protected long
Calculates the Memory Size for this Cell.final int
final int
Compares this Blob to another Blob, in lexicographic order sorting by first bytes (unsigned).int
encodeRaw
(byte[] bs, int pos) Encodes this Blob, excluding tag byte (will include count)boolean
Determines if this Blob is equal to another Blob.boolean
equalsBytes
(byte[] bytes, long byteOffset) Tests if the byte contents of this instance are equal to a subset of a byte arrayboolean
equalsBytes
(ABlob k) Tests if this Blob has exactly the same bytes as another BlobGets a byte buffer containing this Blob's raw data.final int
getBytes
(byte[] dest, int pos) Copies the bytes from this instance to a given destination arrayfinal Hash
Computes the hash of the byte data stored in this Blob, using the default MessageDigest.int
getHexDigit
(long digitPos) Gets the specified hex digit from this data object.byte[]
Gets the internal array backing this Blob.int
Gets this offset into the internal array backing this Blob.getRef
(int i) Gets a numbered child Ref from within this Cell.int
Gets the number of Refs contained within this Cell.long
Computes the length of the longest common hex prefix between two blobslong
Returns the number of matching hex digits in the given hex range of another Blob.boolean
hexMatches
(ABlob key, int start, int end) Tests if a specific range of hex digits are exactly equal.boolean
Returns true if this Blob is a fully packed set of chunksboolean
Returns true if this is a fully packed set of chunkslong
longAt
(long i) long
Converts this BlobLike to the corresponding long value.boolean
rangeMatches
(AArrayBlob b, int start, int end) Tests if a specific range of bytes are exactly equal from this Blob with another Blobboolean
rangeMatches
(ABlob b, int start, int end) Tests if a specific range of bytes are exactly equal.int
read
(long offset, long count, ByteBuffer dest) Gets bytes from this Blob into a ByteBufferfinal short
shortAt
(long i) slice
(long start, long end) Gets a contiguous slice of this Blob, as a new Blob.Converts the contents of this value to a flat array-backed Blob instance.void
updateDigest
(MessageDigest digest) updateRefs
(IRefFunction func) Updates all Refs in this object using the given function.void
validate()
Validates the complete structure of this object.void
Validates the local structure and invariants of this cell.Methods inherited from class convex.core.data.ABlob
computeHash, count, empty, encode, equals, get, getChunk, getElementRef, getTag, getType, hashCode, isCVMValue, print, read, replaceSlice, size, slice, toBlob, toByteBuffer, toCanonical
Methods inherited from class convex.core.data.ABlobLike
getBytes, hexEquals, hexLength, isDataValue, toHexString, toHexString
Methods inherited from class convex.core.data.ACountable
isEmpty
Methods inherited from class convex.core.data.ACell
attachMemorySize, attachRef, cachedEncoding, cachedHash, createEncoding, createRef, equals, genericEquals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getMemorySize, getRef, isCanonical, isEmbedded, toCVMString, toString
Methods inherited from class convex.core.data.AObject
attachEncoding, 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
-
Field Details
-
store
protected final byte[] store -
offset
protected final int offset -
contentHash
Cached hash of the Blob data. Might be null.
-
-
Constructor Details
-
AArrayBlob
protected AArrayBlob(byte[] bytes, int offset, int length)
-
-
Method Details
-
getContentHash
Description copied from class:ABlob
Computes the hash of the byte data stored in this Blob, using the default MessageDigest. This is the correct hash ID for a data value if this blob contains the data value's encoding- Overrides:
getContentHash
in classABlob
- Returns:
- The Hash
-
updateDigest
- Specified by:
updateDigest
in classABlob
-
slice
Description copied from class:ABlob
Gets a contiguous slice of this Blob, as a new Blob. Shares underlying backing data where possible -
append
-
appendSmall
-
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.
-
compareTo
Description copied from class:ABlob
Compares this Blob to another Blob, in lexicographic order sorting by first bytes (unsigned). Note: This means that compareTo does not precisely match equality, because specialised Blob types may be lexicographically equal but represent different values.- Specified by:
compareTo
in interfaceComparable<ABlobLike<?>>
- Overrides:
compareTo
in classABlob
-
compareTo
-
getBytes
public final int getBytes(byte[] dest, int pos) Description copied from class:ABlobLike
Copies the bytes from this instance to a given destination array -
encodeRaw
-
appendHex
Description copied from class:ABlobLike
Append hex string up to the given length in hex digits (a multiple of two) -
isChunkPacked
public boolean isChunkPacked()Description copied from class:ABlob
Returns true if this Blob is a fully packed set of chunks- Overrides:
isChunkPacked
in classABlob
- Returns:
- True if fully packed, 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
-
calcMemorySize
protected long calcMemorySize()Description copied from class:ACell
Calculates the Memory Size for this Cell. Assumes not already calculated Requires any child Refs to be either direct or of persisted in store at minimum, or you might get a MissingDataException- Overrides:
calcMemorySize
in classACell
- Returns:
- Memory Size of this Cell
-
byteAt
-
shortAt
-
longAt
public long longAt(long i) -
byteAtUnchecked
public final byte byteAtUnchecked(long i) Description copied from class:ABlobLike
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.- Overrides:
byteAtUnchecked
in classABlobLike<CVMLong>
- Parameters:
i
- Index of the byte to get- Returns:
- The byte at the specified position
-
getHexDigit
public int getHexDigit(long digitPos) Description copied from class:ABlobLike
Gets the specified hex digit from this data object. WARNING: Result is undefined if index is out of bounds, but probably an IndexOutOfBoundsException.- Overrides:
getHexDigit
in classABlobLike<CVMLong>
- Parameters:
digitPos
- The position of the hex digit- Returns:
- The value of the hex digit, in the range 0-15 inclusive
-
getInternalArray
public byte[] getInternalArray()Gets the internal array backing this Blob. Use with caution!- Returns:
- Byte array backing this blob
-
getInternalOffset
public int getInternalOffset()Gets this offset into the internal array backing this Blob.- Returns:
- Offset into backing array
-
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.
-
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 -
equalsBytes
public boolean equalsBytes(byte[] bytes, long byteOffset) 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 withbyteOffset
- Offset into byte array from which to start comparison- Returns:
- true if exactly equal, false otherwise
-
equalsBytes
Description copied from class:ABlob
Tests if this Blob has exactly the same bytes as another Blob- Specified by:
equalsBytes
in classABlob
- Parameters:
k
- Blob to compare with- Returns:
- True if byte content is exactly equal, false otherwise
-
rangeMatches
Tests if a specific range of bytes are exactly equal.- Parameters:
b
- Blob to compare withstart
- Start index of range (inclusive)end
- End index of range (exclusive)- Returns:
- true if digits are equal, false otherwise
-
rangeMatches
Tests if a specific range of bytes are exactly equal from this Blob with another Blob- Parameters:
b
- Blob with which to comparestart
- Start index in both Blobsend
- End index in both Blobs- Returns:
- true if digits are equal, false otherwise
-
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. -
hexMatches
Tests if a specific range of hex digits are exactly equal.- Parameters:
key
- Blob to compare withstart
- Start hex digit index (inclusive)end
- End hex digit index (Exclusive)- Returns:
- true if digits are equal, false otherwise
-
hexMatch
-
validate
Description copied from interface:IValidated
Validates the complete structure of this object. It is necessary to ensure all child Refs are validated, so the general contract for validate is:- Call super.validate() - which will indirectly call validateCell()
- Call validate() on any contained cells in this class
- Specified by:
validate
in interfaceIValidated
- Overrides:
validate
in classABlob
- Throws:
InvalidDataException
- If the data Value is invalid in any way
-
validateCell
Description copied from class:ACell
Validates the local structure and invariants of this cell. Called by validate() super implementation. Should validate directly contained data, but should not validate all other structure of this cell. In particular, should not traverse potentially missing child Refs.- Overrides:
validateCell
in classABlob
- Throws:
InvalidDataException
- If the Cell is invalid
-
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 -
getRef
Description copied from class:ACell
Gets a numbered child Ref from within this Cell. WARNING: May need to convert to a canonical instance -
updateRefs
Description copied from class:ACell
Updates all Refs in this object using the given function. The function *must not* change the hash value of Refs, in order to ensure structural integrity of modified data structures. The implementation *should* re-attach any original encoding in order to prevent re-encoding or surplus hashing This is a building block for a very sneaky trick that enables use to do a lot of efficient operations on large trees of smart references. Must return the same object if no Refs are altered.- Overrides:
updateRefs
in classACell
- Parameters:
func
- Ref update function- Returns:
- Cell with updated Refs
-
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
-
read
Description copied from class:ABlob
Gets bytes from this Blob into a ByteBuffer
-