Package convex.core.data
Class Address
- All Implemented Interfaces:
IValidated,IWriteable,Comparable<ABlob>
Immutable class representing an Address.
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
contentHashFields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY -
Method Summary
Modifier and TypeMethodDescriptionstatic Addresscreate(long number)Creates an Address from a blob.static AddressCreates an Address from a blob.intencode(byte[] bs, int pos)Writes this Cell's encoding to a byte array, including a tag byte which will be written firstintencodeRaw(byte[] bs, int pos)Writes this Cell's encoding to a byte array, excluding the tag bytebooleanDetermines if this Blob is equal to another Blob.booleanbooleanequalsBytes(byte[] bytes, int byteOffset)Tests if this Blob is equal to a subset of a byte arrayintEstimate the encoded data size for this Cell.static AddressConstructs an Address object from a hex stringvoidgetBytes(byte[] dest, int destOffset)Copies the bytes from this blob to a given destinationbytegetTag()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.booleanReturns true if this Cell is in a canonical format for message writing.booleanReturns true if this object represents a first class CVM Value.booleanReturns true if this object is a regular blob (i.e.longGets 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 AddressConstructs an Address from an arbitrary String, attempting to parse different possible formatsvoidprint(StringBuilder sb)Prints this Object to a readable String Representationstatic AddressreadRaw(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 voidupdateDigest(MessageDigest digest)voidValidates 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, writeToBufferMethods inherited from class convex.core.data.ABlob
compareTo, computeHash, empty, equals, get, getBytes, getContentHash, getElementRef, getHexDigit, hexEquals, hexEquals, hexLength, slice, toByteBuffer, toHexString, validateMethods inherited from class convex.core.data.ACountable
isEmpty, sizeMethods 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, toString, updateRefs, writeMethods 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:ACellGets the most specific known runtime Type for this Cell. -
hashCode
public int hashCode()Description copied from class:ACellGets 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: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 -
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:ACellWrites this Cell's encoding to a byte array, including a tag byte which will be written first- 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
-
print
Description copied from class:AObjectPrints this Object to a readable String Representation -
isCanonical
public boolean isCanonical()Description copied from class:ACellReturns true if this Cell is in a canonical format for message writing. Reading or writing a non-canonical value should be considered illegal, but non-canonical objects may be used on a temporary internal basis.- Overrides:
isCanonicalin classALongBlob- Returns:
- true if the object is in canonical format, false otherwise
-
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 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: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
-
isCVMValue
public final boolean isCVMValue()Description copied from class:ACellReturns 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:
isCVMValuein classALongBlob- Returns:
- true if the object is a CVM Value, false otherwise
-
isRegularBlob
public boolean isRegularBlob()Description copied from class:ABlobReturns true if this object is a regular blob (i.e. not a special blob type like Hash or Address)- Overrides:
isRegularBlobin classABlob- Returns:
- True if a regular blob
-
getBytes
public void getBytes(byte[] dest, int destOffset)Description copied from class:ABlobCopies the bytes from this blob to a given destination -
slice
Description copied from class:ABlobGets a contiguous slice of this blob, as a new Blob. Shares underlying backing data where possible -
toBlob
Description copied from class:ABlobConverts this object to a Blob instance -
updateDigest
- Specified by:
updateDigestin classABlob
-
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
-
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 -
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 -
getTag
public byte getTag()Description copied from class:ACellGets the tag byte for this cell. The tag byte will be the first byte of the encoding -
toCanonical
Description copied from class:ACellConverts this Cell to its canonical version. Returns this if already canonical- Specified by:
toCanonicalin 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
-