Package convex.core.data
Class Keyword
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.data.ASymbolic
convex.core.data.Keyword
- All Implemented Interfaces:
IValidated,IWriteable,Comparable<Keyword>
Keyword data type. Intended as human-readable map keys, tags and option
specifiers etc.
Keywords evaluate to themselves, and as such can be considered as literal
constants.
"Programs must be written for people to read, and only incidentally for
machines to execute." ― Harold Abelson
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMaximum size of a Keyword in UTF-8 bytes representationstatic final intMinimum size of a Keyword in UTF-8 bytes representationFields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY -
Method Summary
Modifier and TypeMethodDescriptionintstatic KeywordCreates a Keyword with the given namestatic KeywordCreates a Keyword with the given namestatic KeywordcreateChecked(AString aString) Creates a Keyword with the given name, throwing an exception if name is not validstatic KeywordcreateChecked(String aString) 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.intEstimate the encoded data size for 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.booleanReturns true if this Cell is in a canonical representation for message writing.booleanprint(BlobBuilder bb, long limit) Prints this Object to a readable String Representation.static Keywordread(ByteBuffer bb) Reads a Keyword from the given ByteBuffer, assuming tag already consumedConverts this Cell to its canonical version.toCVMString(long limit) Returns the CVM String representation of this Cell.static KeywordunsafeCreate(StringShort rawName) Creates a Keyword in an unsafe manner (possibly invalid name), used for testingstatic KeywordunsafeCreate(String rawName) Creates a Keyword in an unsafe manner (possibly invalid name), used for testingvoidValidates this Symbolic valueMethods inherited from class convex.core.data.ASymbolic
calcMemorySize, createRef, getName, hashCode, isCVMValue, isEmbedded, validateNameMethods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, createAnnounced, createEncoding, createPersisted, createPersisted, equals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, isCompletelyEncoded, mark, mark, toString, updateRefs, validate, writeMethods inherited from class convex.core.data.AObject
attachEncoding, print, print
-
Field Details
-
MAX_CHARS
public static final int MAX_CHARSMaximum size of a Keyword in UTF-8 bytes representation- See Also:
-
MIN_CHARS
public static final int MIN_CHARSMinimum size of a Keyword in UTF-8 bytes representation- See Also:
-
-
Method Details
-
getType
Description copied from class:ACellGets the most specific known runtime Type for this Cell. -
create
Creates a Keyword with the given name- Parameters:
name- A String to use as the keyword name- Returns:
- The new Keyword, or null if the name is invalid for a Keyword
-
unsafeCreate
Creates a Keyword in an unsafe manner (possibly invalid name), used for testing- Parameters:
rawName- Raw Keyword name- Returns:
- Possibly invalid Keyword
-
unsafeCreate
Creates a Keyword in an unsafe manner (possibly invalid name), used for testing- Parameters:
rawName- Raw Keyword name- Returns:
- Possibly invalid Keyword
-
create
Creates a Keyword with the given name- Parameters:
name- A String to use as the keyword name- Returns:
- The new Keyword, or null if the name is invalid for a Keyword
-
createChecked
Creates a Keyword with the given name, throwing an exception if name is not valid- Parameters:
aString- A String of at least 1 and no more than 64 UTF-8 bytes in length- Returns:
- The new Keyword
-
createChecked
-
isCanonical
public boolean isCanonical()Description copied from class:ACellReturns 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).- Specified by:
isCanonicalin classACell- Returns:
- true if the object is in canonical format, false otherwise
-
read
Reads a Keyword from the given ByteBuffer, assuming tag already consumed- Parameters:
bb- ByteBuffer source- Returns:
- The Keyword read
- Throws:
BadFormatException- If a Keyword could not be read correctly
-
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 if limit of printing is exceeded otherwise DoS attacks may be possible. -
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.- Specified by:
estimatedEncodingSizein interfaceIWriteable- Returns:
- The estimated size for the binary representation of this object.
-
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. -
compareTo
- Specified by:
compareToin interfaceComparable<Keyword>
-
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.- Specified by:
getRefCountin classACell- 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 written as the first byte of the Cell's Encoding -
toCanonical
Description copied from class:ACellConverts this Cell to its canonical version. Returns this Cell if already canonical, may be O(n) in size of value otherwise.- 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. MUST return null in O(1) time if the length of the CVM String would exceed limit. 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
-