Package convex.core.data
Class Symbol
- All Implemented Interfaces:
IValidated,IWriteable,Comparable<ABlobLike<?>>
Class representing a Symbol. Symbols are more commonly used in CVM code to refer to functions and values in the execution environment.
Symbols are simply small immutable data Objects, and can be used freely in data structures. They can be used as map keys, however for most normal circumstances Strings or Keywords are more appropriate as keys.
A Symbol comprises: - A name
"Becoming sufficiently familiar with something is a substitute for understanding it." - John Conway
-
Field Summary
FieldsFields inherited from class convex.core.data.ACell
cachedRef, memorySize -
Method Summary
Modifier and TypeMethodDescriptionintintstatic SymbolCreates a Symbol with the given name.static SymbolCreates a Symbol with the given nameintencode(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.booleanTests if this Symbol is equal to another Symbol.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.booleanReturns true if this Cell is in a canonical representation.booleanprint(BlobBuilder bb, long limit) Prints this Object to a readable String Representation.static SymbolReads a Symbol from the given Blobslice(long start, long end) Gets a slice of this data structureConverts this Cell to a canonical version.toCVMString(long limit) Returns the CVM String representation of this Cell.static SymbolunsafeCreate(StringShort rawName) Creates a Symbol in an unsafe manner (possibly invalid name), used for testingstatic SymbolunsafeCreate(String rawName) Creates a Symbol in an unsafe manner (possibly invalid name), used for testingvoidValidates this Symbolic valueMethods inherited from class convex.core.data.ASymbolic
byteAt, calcMemorySize, count, createRef, empty, equalsBytes, estimatedEncodingSize, get, getBytes, getElementRef, getName, getRef, hashCode, hexMatch, isCVMValue, isDataValue, isEmbedded, longValue, toBlob, updateRefs, validateNameMethods inherited from class convex.core.data.ABlobLike
appendHex, byteAtUnchecked, getBytes, getHexDigit, hexEquals, hexLength, hexMatch, toFlatBlob, toHexString, toHexStringMethods inherited from class convex.core.data.ACountable
isEmpty, size, sliceMethods inherited from class convex.core.data.ACell
attachMemorySize, attachRef, cachedEncoding, cachedHash, createEncoding, equals, genericEquals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getMemorySize, getRef, toString, validateMethods inherited from class convex.core.data.AObject
attachEncoding, print, print
-
Field Details
-
cache
-
-
Method Details
-
getType
-
create
-
create
-
unsafeCreate
-
unsafeCreate
Creates a Symbol in an unsafe manner (possibly invalid name), used for testing- Parameters:
rawName- Raw Symbol name- Returns:
- Possibly invalid Keyword
-
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
Tests if this Symbol is equal to another Symbol. Equality is defined by both namespace and name being equal.- Parameters:
sym- Symbol to compare with- Returns:
- true if Symbols are equal, false otherwise
-
compareTo
-
compareTo
-
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. -
read
Reads a Symbol from the given Blob- Parameters:
blob- Encoding source- Returns:
- The Symbol read
- Throws:
BadFormatException- If a Symbol could not be read correctly.
-
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
-
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. -
validateCell
Description copied from class:ASymbolicValidates this Symbolic value- Specified by:
validateCellin classASymbolic- Throws:
InvalidDataException- If the symbolic value is invalid
-
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 classASymbolic- Returns:
- The number of Refs in this Cell
-
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
-
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
-
slice
Description copied from class:ACountableGets a slice of this data structure
-