Package convex.core.data
Class AArrayBlob
- All Implemented Interfaces:
IValidated,IWriteable,Comparable<ABlob>
- Direct Known Subclasses:
AccountKey,Blob,Hash
Abstract base class for binary data stored in Java arrays.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final intprotected final intprotected final byte[]Fields inherited from class convex.core.data.ABlob
contentHashFields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAppend an additional Blob to this, creating a new Blob as needed.final booleanappendHex(BlobBuilder bb, long hexLength) Append hex string up to the given length in hex digits (a multiple of two)protected ABlobappendSmall(ABlob d) final bytebyteAt(long i) Gets the byte at the specified position in this bloblongComputes the length of the longest common hex prefix between two blobsfinal intfinal intCompares this Blob to another Blob, in lexicographic order sorting by first bytes (unsigned).final longcount()Gets the length of this Blobfinal intencodeRaw(byte[] bs, int pos) Encodes this Blob, excluding tag byte (will include count)intencodeRawData(byte[] bs, int pos) Encodes the raw data of this Blob.booleanDetermines if this Blob is equal to another Blob.booleanequalsBytes(byte[] bytes, int byteOffset) Tests if this Blob is equal to a subset of a byte arraybooleanequalsBytes(ABlob k) Tests if this Blob has exactly the same bytes as another BlobGets a byte buffer containing this Blob's raw data.final voidgetBytes(byte[] dest, int destOffset) Copies the bytes from this blob to a given destinationintgetHexDigit(long digitPos) Gets the specified hex digit from this data object.byte[]Gets the internal array backing this Blob.intGets this offset into the internal array backing this Blob.final intGets the number of Refs contained within this Cell.final bytegetTag()Gets the tag byte for this cell.final bytegetUnchecked(long i) Gets the byte at the specified position in this data object, without bounds checking.booleanhexMatches(ABlob key, int start, int end) Tests if a specific range of hex digits are exactly equal.longhexMatchLength(ABlob b, long start, long length) Returns the number of matching hex digits in the given hex range of another Blob.longGets the long value of this Blob if the length is exactly 8 bytes, otherwise throws an ExceptionbooleanrangeMatches(AArrayBlob b, int start, int end) Tests if a specific range of bytes are exactly equal from this Blob with another BlobbooleanrangeMatches(ABlob b, int start, int end) Tests if a specific range of bytes are exactly equal.slice(long start, long end) Gets a contiguous slice of this Blob, as a new Blob.Converts this object to a flat array-backed Blob instance.longtoLong()Converts this Blob to the corresponding long value.voidupdateDigest(MessageDigest digest) voidvalidate()Validates the complete structure of this object.voidValidates the local structure and invariants of this cell.intwriteToBuffer(byte[] bs, int pos) Writes the raw byte contents of this blob to a byte arrayWrites the raw byte contents of this Blob to a ByteBuffer.Methods inherited from class convex.core.data.ABlob
computeHash, empty, equals, get, getBytes, getChunk, getContentHash, getElementRef, getType, hashCode, hexEquals, hexEquals, hexLength, isCVMValue, isRegularBlob, print, slice, toByteBuffer, toCanonical, toHexString, toHexStringMethods inherited from class convex.core.data.ACountable
isEmpty, sizeMethods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, encode, equals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, isCanonical, isCompletelyEncoded, isEmbedded, mark, mark, toCVMString, toString, updateRefs, writeMethods inherited from class convex.core.data.AObject
attachEncoding, print, printMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface convex.core.data.IWriteable
estimatedEncodingSize
-
Field Details
-
store
protected final byte[] store -
offset
protected final int offset -
length
protected final int length
-
-
Constructor Details
-
AArrayBlob
protected AArrayBlob(byte[] bytes, int offset, int length)
-
-
Method Details
-
updateDigest
- Specified by:
updateDigestin classABlob
-
slice
Description copied from class:ABlobGets a contiguous slice of this Blob, as a new Blob. Shares underlying backing data where possible -
append
Description copied from class:ABlobAppend an additional Blob to this, creating a new Blob as needed. New Blob will be canonical. -
appendSmall
-
toFlatBlob
Description copied from class:ABlobConverts this object to a flat array-backed Blob instance. Warning: might be O(n) in size of Blob, may not be canonical etc.- Specified by:
toFlatBlobin classABlob- Returns:
- A Blob instance containing the same data as this Blob.
-
compareTo
Description copied from class:ABlobCompares 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:
compareToin interfaceComparable<ABlob>- Overrides:
compareToin classABlob
-
compareTo
-
getBytes
public final void getBytes(byte[] dest, int destOffset) Description copied from class:ABlobCopies the bytes from this blob to a given destination -
writeToBuffer
Description copied from class:ABlobWrites the raw byte contents of this Blob to a ByteBuffer. May be big!- Specified by:
writeToBufferin classABlob- Parameters:
bb- ByteBuffer to write to- Returns:
- The passed ByteBuffer, after writing byte content
-
writeToBuffer
public int writeToBuffer(byte[] bs, int pos) Description copied from class:ABlobWrites the raw byte contents of this blob to a byte array- Specified by:
writeToBufferin classABlob- Parameters:
bs- Byte array to write topos- Starting position in byte array to write to- Returns:
- The position in the array after writing
-
encodeRaw
public final int encodeRaw(byte[] bs, int pos) Encodes this Blob, excluding tag byte (will include count) -
encodeRawData
public int encodeRawData(byte[] bs, int pos) Encodes the raw data of this Blob. Assumes buffer has enough space for (length) bytes.- Overrides:
encodeRawDatain classABlob- Parameters:
bs- Byte array to write topos- Position to write at- Returns:
- Updates position
-
appendHex
Description copied from class:ABlobAppend hex string up to the given length in hex digits (a multiple of two) -
count
public final long count()Description copied from class:ABlobGets the length of this Blob -
byteAt
public final byte byteAt(long i) Description copied from class:ABlobGets the byte at the specified position in this blob -
getUnchecked
public final byte getUnchecked(long i) Description copied from class:ABlobGets the byte at the specified position in this data object, without bounds checking. Only safe if index is known to be in bounds, otherwise result is undefined.- Specified by:
getUncheckedin classABlob- 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:ABlobGets the specified hex digit from this data object. WARNING: Result is undefined if index is out of bounds, but probably an IndexOutOfBoundsException.- Overrides:
getHexDigitin classABlob- 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:ABlobGets a byte buffer containing this Blob's raw data. Will have remaining bytes equal to this Blob's size.- Specified by:
getByteBufferin classABlob- Returns:
- A ByteBuffer containing the Blob's data.
-
equals
Description copied from class:ABlobDetermines if this Blob is equal to another Blob. Blobs are defined to be equal if they have the same on-chain representation, i.e. if and only if all of the following are true: - Blob is of the same general type - Blobs are of the same length - All byte values are equal -
equalsBytes
public boolean equalsBytes(byte[] bytes, int byteOffset) Description copied from class:ABlobTests if this Blob is equal to a subset of a byte array- Specified by:
equalsBytesin classABlob- Parameters:
bytes- Byte array to compare withbyteOffset- Offset into byte array- Returns:
- true if exactly equal, false otherwise
-
equalsBytes
Description copied from class:ABlobTests if this Blob has exactly the same bytes as another Blob- Specified by:
equalsBytesin 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
-
hexMatchLength
Description copied from class:ABlobReturns 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.- Specified by:
hexMatchLengthin classABlob- 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
-
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
-
commonHexPrefixLength
Description copied from class:ABlobComputes the length of the longest common hex prefix between two blobs- Specified by:
commonHexPrefixLengthin classABlob- Parameters:
b- Blob to compare with- Returns:
- The length of the longest common prefix in hex digits
-
validate
Description copied from interface:IValidatedValidates 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:
validatein interfaceIValidated- Overrides:
validatein classABlob- Throws:
InvalidDataException- If the data Value is invalid in any way
-
validateCell
Description copied from class:ACellValidates 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:
validateCellin classABlob- Throws:
InvalidDataException- If the Cell is invalid
-
longValue
public long longValue()Description copied from class:ABlobGets the long value of this Blob if the length is exactly 8 bytes, otherwise throws an Exception -
toLong
public long toLong()Description copied from class:ABlobConverts this Blob to the corresponding long value. Assumes big-endian format, as if the entire blob is interpreted as a big integer. Higher bytes outside the Long range will be ignored. -
getTag
public final byte getTag()Description copied from class:ACellGets the tag byte for this cell. The tag byte is always written as the first byte of the Cell's Encoding -
getRefCount
public final int getRefCount()Description copied from class:ACellGets 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.- Specified by:
getRefCountin classACell- Returns:
- The number of Refs in this Cell
-