Package convex.core.data
Class Address
- All Implemented Interfaces:
IValidated,IWriteable,Comparable<ABlobLike<?>>
Immutable class representing an Address, generally used to uniquely identify an Account.
An Address is a specialised 8-byte long blob instance that wraps a non-negative long Account number. This number
serves as an index into the vector of accounts for the current state.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final AddressThe maximum possible Addressstatic final AddressThe Zero AddressFields inherited from class convex.core.data.ACell
cachedRef, memorySize -
Method Summary
Modifier and TypeMethodDescriptionfinal bytebyteAt(long i) Gets the byte at the specified position.final bytebyteAtUnchecked(long i) Gets the byte at the specified position in this data object, possibly skipping bounds checking.protected longCalculates the Memory Size for this Cell.protected intcompareTo(long bvalue) intlongcount()Returns the number of elements in this valuestatic Addresscreate(long number) Obtains an Address.static AddressObtains an Address from a blob.empty()Returns a canonical, singleton empty instance of the same type as this Countable value.intencode(byte[] bs, int pos) Writes this Cell's encoding to a byte array, including a tag byte which will be written first.intencodeRaw(byte[] bs, int pos) Writes this Cell's encoding to a byte array, excluding the tag byte.booleanChecks for equality with another Cell.final booleanbooleanbooleanequalsBytes(ABlob b) Compare the byte content of this BlobLike to a Blob valueintEstimate the encoded data size for this Cell.static AddressObtains an Address from a hex stringget(long i) Gets the element at the specified element index in this valuefinal intgetBytes(byte[] bs, int pos) Copies the bytes from this instance to a given destination arraygetRef(int i) Gets a numbered child Ref from within this Cell.intGets the number of Refs contained within this Cell.bytegetTag()Gets the tag byte for this cell.getType()Gets the most specific known runtime Type for this Cell.inthashCode()Gets the Java hashCode for this cell.longReturns the number of matching hex digits in the given hex range of another Blob.booleanReturns true if this Cell is in a canonical representation.booleanReturns true if this cell is a first class CVM Value allowable in the CVM state Sub-structural cells that are not themselves first class values should return false Records and types that are not permissible on the CVM should return false.longConverts this BlobLike to the corresponding long value.offset(long offset) Creates a new Address at an offset to this Addressstatic AddressAttempts to parse an address from an arbitrary object.static AddressObtains an Address from an arbitrary String, attempting to parse possible formats '123' '0xc3' or '#123'booleanprint(BlobBuilder sb, long limit) Prints this Object to a readable String Representation.static Addressslice(long start, long end) Gets a slice of this data structuretoBlob()Convert this BlobLike object to an ABlob instance, in the most efficient way.Converts this Cell to a canonical version.toCVMString(long limit) Returns the CVM String representation of this Cell.Converts the contents of this value to a flat array-backed Blob instance.toString()Returns the Java String representation of this Cell.static AddressunsafeCreate(long number) Creates an Address without checking.updateRefs(IRefFunction func) Updates all Refs in this object using the given function.voidValidates the local structure and invariants of this cell.Methods inherited from class convex.core.data.ABlobLike
appendHex, getBytes, getElementRef, getHexDigit, hexEquals, hexLength, hexMatch, isDataValue, toHexString, toHexStringMethods inherited from class convex.core.data.ACountable
isEmpty, size, sliceMethods inherited from class convex.core.data.ACell
attachMemorySize, attachRef, cachedEncoding, cachedHash, createEncoding, createRef, genericEquals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getMemorySize, getRef, isEmbedded, validateMethods inherited from class convex.core.data.AObject
attachEncoding, print, print
-
Field Details
-
LENGTH
public static final int LENGTH- See Also:
-
ZERO
The Zero Address -
MAX_VALUE
The maximum possible Address -
MAX_ENCODING_LENGTH
public static final int MAX_ENCODING_LENGTH- See Also:
-
-
Method Details
-
create
Obtains an Address. Number must be a valid non-negative long value.- Parameters:
number- Account number- Returns:
- Address instance, or null if not valid
-
unsafeCreate
Creates an Address without checking.- Parameters:
number- Account number- Returns:
- Address instance, may be invalid
-
create
-
getType
-
hashCode
public int hashCode()Description copied from class:ACellGets the Java hashCode for this cell. Must be consistent with equals. Default is the hashCode of the Encoding blob, since this is consistent with encoding-based equality. However, different Types may provide more efficient hashcodes provided that the usual invariants are preserved -
equals
-
equals
Description copied from class:ACellChecks for equality with another Cell. In general, Cells are considered equal if they have the same canonical representation, i.e. an identical encoding with the same hash value. Subclasses SHOULD override this if they have a more efficient equals implementation. MUST NOT require reads from Store. -
equals
-
fromHex
-
parse
-
parse
-
read
- Throws:
BadFormatException
-
encode
public int encode(byte[] bs, int pos) Description copied from class:ACellWrites this Cell's encoding to a byte array, including a tag byte which will be written first. Cell must be canonical, or else an error may occur.- Specified by:
encodein interfaceIWriteable- Specified by:
encodein classACell- Parameters:
bs- A byte array to which to write the encodingpos- The offset into the byte array- Returns:
- New position after writing
-
encodeRaw
public int encodeRaw(byte[] bs, int pos) Description copied from class:ACellWrites this Cell's encoding to a byte array, excluding the tag byte. -
print
Description copied from class:AObjectPrints this Object to a readable String Representation. SECURITY: Must halt and return false in O(1) time when limit of printing is exceeded otherwise DoS attacks may be possible. -
toCVMString
Description copied from class:ACellReturns the CVM String representation of this Cell. Normally, this is as printed, but may be different for some types. SHOULD return null in O(1) time if the length of the CVM String can be proved to exceed the limit. MUST complete in O(limit) time and space otherwise The String representation is intended to be a easy-to-read textual representation of the Cell's data content.- Overrides:
toCVMStringin classACell- Parameters:
limit- Limit of CVM String length in UTF-8 bytes- Returns:
- CVM String, or null if limit exceeded
-
toString
-
estimatedEncodingSize
public int estimatedEncodingSize()Description copied from interface:IWriteableEstimate 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.
-
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.- Specified by:
validateCellin classACell- Throws:
InvalidDataException- If the Cell is invalid
-
slice
Description copied from class:ACountableGets a slice of this data structure- Specified by:
slicein classACountable<CVMLong>- Parameters:
start- Start index (inclusive)end- end index (exclusive)- Returns:
- Slice of data structure, or null if invalid slice
-
toFlatBlob
Description copied from class:ABlobLikeConverts 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.- Overrides:
toFlatBlobin classABlobLike<CVMLong>- Returns:
- A Blob instance containing the same data as this value. Might be `this` if already a flat Blob.
-
getTag
public byte getTag()Description copied from class:ACellGets the tag byte for this cell. The tag byte is always equal to the first byte of the Cell's canonical Encoding, and is sufficient to distinguish how to read the rest of the encoding. -
toCanonical
Description copied from class:ACellConverts 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:
toCanonicalin classACell- Returns:
- Canonical version of Cell
-
offset
Creates a new Address at an offset to this Address- Parameters:
offset- Offset to add to this Address (may be negative)- Returns:
- New Address, or null if would be invalid
-
byteAt
-
byteAtUnchecked
public final byte byteAtUnchecked(long i) Description copied from class:ABlobLikeGets 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:
byteAtUncheckedin classABlobLike<CVMLong>- Parameters:
i- Index of the byte to get- Returns:
- The byte at the specified position
-
hexMatch
Description copied from class:ABlobLikeReturns 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. -
empty
Description copied from class:ACountableReturns a canonical, singleton empty instance of the same type as this Countable value. -
getBytes
public final int getBytes(byte[] bs, int pos) Description copied from class:ABlobLikeCopies the bytes from this instance to a given destination array -
longValue
public long longValue()Description copied from class:ABlobLikeConverts 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 -
toBlob
-
equalsBytes
Description copied from class:ABlobLikeCompare the byte content of this BlobLike to a Blob value- Specified by:
equalsBytesin classABlobLike<CVMLong>- Parameters:
b- Blob value to compare with- Returns:
- `true` if byte contents are exactly equal, `false` otherwise
-
compareTo
-
compareTo
protected int compareTo(long bvalue) -
count
public long count()Description copied from class:ACountableReturns the number of elements in this value- Specified by:
countin classACountable<CVMLong>- Returns:
- Number of elements
-
get
Description copied from class:ACountableGets the element at the specified element index in this value- Specified by:
getin classACountable<CVMLong>- Parameters:
i- Index of element to get- Returns:
- Element at the specified index
-
isCanonical
public boolean isCanonical()Description copied from class:ACellReturns 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:
isCanonicalin classACell- Returns:
- true if the object is in canonical format, false otherwise
-
calcMemorySize
protected long calcMemorySize()Description copied from class:ACellCalculates 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:
calcMemorySizein classACell- Returns:
- Memory Size of this Cell
-
isCVMValue
public boolean isCVMValue()Description copied from class:ACellReturns true if this cell is a first class CVM Value allowable in the CVM state Sub-structural cells that are not themselves first class values should return false Records and types that are not permissible on the CVM should return false. Pretty much everything else should return true. Note: CVM values might not be in a canonical format, e.g. temporary data structures- Specified by:
isCVMValuein classACell- Returns:
- true if the object is a CVM Value, false otherwise
-
getRef
Description copied from class:ACellGets a numbered child Ref from within this Cell. WARNING: May need to convert to a canonical instance -
updateRefs
Description copied from class:ACellUpdates 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:
updateRefsin classACell- Parameters:
func- Ref update function- Returns:
- Cell with updated Refs
-
getRefCount
public 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.- Overrides:
getRefCountin classACell- Returns:
- The number of Refs in this Cell
-