Package convex.core.data
Class Address
- All Implemented Interfaces:
IValidated
,IWriteable
,Comparable<ABlob>
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
FieldsFields inherited from class convex.core.data.ABlob
contentHash
Fields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY
-
Method Summary
Modifier and TypeMethodDescriptionstatic Address
create(long number)
Creates an Address from a blob.static Address
Creates an Address from a blob.int
encode(byte[] bs, int pos)
Writes this Cell's encoding to a byte array, including a tag byte which will be written firstint
encodeRaw(byte[] bs, int pos)
Writes this Cell's encoding to a byte array, excluding the tag byteboolean
Determines if this Blob is equal to another Blob.boolean
boolean
equalsBytes(byte[] bytes, int byteOffset)
Tests if this Blob is equal to a subset of a byte arrayint
Estimate the encoded data size for this Cell.static Address
Constructs an Address object from a hex stringvoid
getBytes(byte[] dest, int destOffset)
Copies the bytes from this blob to a given destinationbyte
getTag()
Gets the tag byte for this cell.getType()
Gets the most specific known runtime Type for this Cell.int
hashCode()
Gets the Java hashCode for this cell.boolean
Returns true if this Cell is in a canonical representation for message writing.boolean
Returns true if this object represents a first class CVM Value.boolean
Returns true if this object is a regular blob (i.e.long
Gets the long value of this Blob if the length is exactly 8 bytes, otherwise throws an Exceptionoffset(long offset)
Creates a new Address at an offset to this Addressstatic Address
Constructs an Address from an arbitrary String, attempting to parse different possible formatsvoid
print(StringBuilder sb)
Prints this Object to a readable String Representationstatic Address
readRaw(ByteBuffer bb)
slice(long start, long length)
Gets a contiguous slice of this blob, as a new Blob.toBlob()
Converts this object to a Blob instanceConverts this Cell to its canonical version.protected void
updateDigest(MessageDigest digest)
void
Validates the local structure and invariants of this cell.Methods inherited from class convex.core.data.ALongBlob
append, byteAt, calcMemorySize, commonHexPrefixLength, count, createRef, equalsBytes, getByteBuffer, getChunk, getRefCount, getUnchecked, hexMatchLength, isEmbedded, toHexString, toHexString, toLong, writeToBuffer, writeToBuffer
Methods inherited from class convex.core.data.ABlob
compareTo, computeHash, empty, equals, get, getBytes, getContentHash, getElementRef, getHexDigit, hexEquals, hexEquals, hexLength, slice, toByteBuffer, toHexString, validate
Methods inherited from class convex.core.data.ACountable
isEmpty, size
Methods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, createAnnounced, createEncoding, createPersisted, createPersisted, equals, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, mark, mark, toString, updateRefs, write
Methods inherited from class convex.core.data.AObject
attachEncoding, print
-
Field Details
-
ZERO
-
MAX_ENCODING_LENGTH
public static final int MAX_ENCODING_LENGTH- See Also:
- Constant Field Values
-
-
Method Details
-
create
Creates an Address from a blob. Number be a valid non-negative long value.- Parameters:
number
- Account number- Returns:
- Address instance, or null if not valid
-
create
Creates an Address from a blob. Must be a valid long value- Parameters:
b
- Blob to convert to an Address- Returns:
- Address instance, or null if not valid
-
getType
Description copied from class:ACell
Gets the most specific known runtime Type for this Cell. -
hashCode
public int hashCode()Description copied from class:ACell
Gets the Java hashCode for this cell. Must be consistent with equals. Default is the first bytes (big-endian) of the Cell Encoding's hash, since this is consistent with encoding-based equality. However, different Types may provide more efficient hashcodes provided that the usual invariants are preserved -
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 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 -
equals
-
fromHex
Constructs an Address object from a hex string- Parameters:
hexString
- String to read Address from- Returns:
- An Address constructed from the hex string, or null if not a valid hex string
-
parse
Constructs an Address from an arbitrary String, attempting to parse different possible formats- Parameters:
s
- String to parse- Returns:
- Address parsed, or null if not valid
-
readRaw
- Throws:
BadFormatException
-
encode
public int encode(byte[] bs, int pos)Description copied from class:ACell
Writes this Cell's encoding to a byte array, including a tag byte which will be written first- Specified by:
encode
in interfaceIWriteable
- Specified by:
encode
in classACell
- Parameters:
bs
- A byte array to which to write the encodingpos
- The offset into the byte array- Returns:
- New position after writing
-
print
Description copied from class:AObject
Prints this Object to a readable String Representation -
isCanonical
public boolean isCanonical()Description copied from class:ACell
Returns true if this Cell is in a canonical representation for message writing. Non-canonical objects may be used on a temporary internal basis, they must always be converted to canonical representations for external use (e.g. Encoding).- Overrides:
isCanonical
in classALongBlob
- Returns:
- true if the object is in canonical format, false otherwise
-
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 likely to contain the entire object when represented in binary format, including the tag byte.- Returns:
- The estimated size for the binary representation of this object.
-
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
-
isCVMValue
public final boolean isCVMValue()Description copied from class:ACell
Returns true if this object represents a first class CVM Value. Sub-structural cells that are not themselves first class values should return false. CVM values might not be in a canonical format, e.g. temporary data structures- Overrides:
isCVMValue
in classALongBlob
- Returns:
- true if the object is a CVM Value, false otherwise
-
isRegularBlob
public boolean isRegularBlob()Description copied from class:ABlob
Returns true if this object is a regular blob (i.e. not a special blob type like Address)- Overrides:
isRegularBlob
in classABlob
- Returns:
- True if a regular blob
-
getBytes
public void getBytes(byte[] dest, int destOffset)Description copied from class:ABlob
Copies the bytes from this blob to a given destination -
slice
Description copied from class:ABlob
Gets a contiguous slice of this blob, as a new Blob. Shares underlying backing data where possible -
toBlob
Description copied from class:ABlob
Converts this object to a Blob instance -
updateDigest
- Specified by:
updateDigest
in classABlob
-
equalsBytes
public boolean equalsBytes(byte[] bytes, int byteOffset)Description copied from class:ABlob
Tests if this Blob is equal to a subset of a byte array- Specified by:
equalsBytes
in classABlob
- Parameters:
bytes
- Byte array to compare withbyteOffset
- Offset into byte array- Returns:
- true if exactly equal, false otherwise
-
longValue
public long longValue()Description copied from class:ABlob
Gets the long value of this Blob if the length is exactly 8 bytes, otherwise throws an Exception -
encodeRaw
public int encodeRaw(byte[] bs, int pos)Description copied from class:ACell
Writes this Cell's encoding to a byte array, excluding the tag byte -
getTag
public byte getTag()Description copied from class:ACell
Gets the tag byte for this cell. The tag byte is always written as the first byte of the Cell's Encoding -
toCanonical
Description copied from class:ACell
Converts this Cell to its canonical version. Returns this Cell if already canonical.- Specified by:
toCanonical
in classABlob
- 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
-