Package convex.core.data
Class Syntax
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.data.Syntax
- All Implemented Interfaces:
IValidated,IWriteable
Class representing a Syntax Object.
A Syntax Object wraps:
- A Form (which may contain nested Syntax Objects)
- Metadata for the Syntax Object, which may be any arbitrary hashmap
-
Field Summary
FieldsFields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY -
Method Summary
Modifier and TypeMethodDescriptionstatic SyntaxWraps a value as a Syntax Object with empty metadata.static SyntaxWraps a value as a Syntax Object, adding the given new metadatastatic SyntaxcreateUnchecked(ACell value, AHashMap<ACell,ACell> meta)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 byteintEstimate the encoded data size for this Cell.getEnd()getMeta()Gets the metadata for this syntax object.getRef(int i)Gets a numbered child Ref from within this Cell.intGets the number of Refs contained within this Cell.getStart()bytegetTag()Gets the tag byte for this cell.getType()Gets the most specific known runtime Type for this Cell.<R> RgetValue()Gets the value datum from this Syntax ObjectbooleanReturns true if this Cell is in a canonical format for message writing.booleanReturns true if this object represents a first class CVM Value.static SyntaxMerge metadata into a Cell, after wrapping as a Syntax ObjectMerges metadata into this syntax object, overriding existing metadatastatic SyntaxWraps a value as a Syntax Object with empty metadata.static SyntaxCreate a Syntax Object with the given value.voidprint(StringBuilder sb)Prints this Object to a readable String Representationstatic Syntaxread(ByteBuffer bb)Converts this Cell to its canonical version.toString()Returns the String representation of this Cell.static <R> RUnwraps a Syntax Object to get the underlying value.static <R extends ACell>
RRecursively unwraps a Syntax objectupdateRefs(IRefFunction func)Updates all Refs in this object using the given function.voidvalidate()Validates the complete structure of this object.voidValidates the local structure and invariants of this cell.Replaces metadata on this Syntax Object.Removes all metadata from this Syntax ObjectMethods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, equals, equals, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, hashCode, isEmbedded, writeMethods inherited from class convex.core.data.AObject
attachEncoding, print
-
Field Details
-
EMPTY
-
-
Method Details
-
getType
Description copied from class:ACellGets the most specific known runtime Type for this Cell. -
createUnchecked
-
create
Wraps a value as a Syntax Object, adding the given new metadata- Parameters:
value- Value to wrap in Syntax Objectmeta- Metadata to merge, may be null- Returns:
- Syntax instance
-
create
Wraps a value as a Syntax Object with empty metadata. Does not change existing Syntax objects.- Parameters:
value- Any CVM value- Returns:
- Syntax instance
-
of
Wraps a value as a Syntax Object with empty metadata. Does not change existing Syntax objects.- Parameters:
value- Any value, will be converted to valid CVM type- Returns:
- Syntax instance
-
of
Create a Syntax Object with the given value. Converts to appropriate CVM type as a convenience- Parameters:
value- Value to wrap- Returns:
- Syntax instance
-
getValue
public <R> R getValue()Gets the value datum from this Syntax Object- Type Parameters:
R- Expected datum type from Syntax object- Returns:
- Value datum
-
getMeta
Gets the metadata for this syntax object. May be empty, but never null.- Returns:
- Metadata for this Syntax Object as a hashmap
-
getStart
-
getEnd
-
getSource
-
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.- Specified by:
isCanonicalin classACell- Returns:
- true if the object is in canonical format, false otherwise
-
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- Specified by:
isCVMValuein classACell- Returns:
- true if the object is a CVM Value, false otherwise
-
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- 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 -
toString
Description copied from class:ACellReturns the String representation of this Cell. The String representation is intended to be a easy-to-read textual representation of the Cell's data content. -
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
-
validate
Description copied from interface:IValidatedValidates the complete structure of this object. It is necessary to ensure all child Refs are validated, so the general contract for validate is:- Call super.validate() - which will indirectly call validateCell()
- Call validate() on any contained cells in this class
- Specified by:
validatein interfaceIValidated- Overrides:
validatein classACell- Throws:
InvalidDataException- If the data Valie is invalid in any way
-
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.
-
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. Contained Refs may be either external or embedded.- Specified by:
getRefCountin classACell- Returns:
- The number of Refs in this Cell
-
getRef
Description copied from class:ACellGets a numbered child Ref from within this Cell. -
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. 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
-
mergeMeta
Merges metadata into this syntax object, overriding existing metadata- Parameters:
additionalMetadata- Extra metadata to merge- Returns:
- Syntax Object with updated metadata
-
mergeMeta
Merge metadata into a Cell, after wrapping as a Syntax Object- Parameters:
original- Cell to enhance with merged metadataadditional- Syntax Object containing additional metadata. Any value will be ignored.- Returns:
- Syntax object with merged metadata
-
withMeta
Replaces metadata on this Syntax Object. Old metadata is discarded.- Parameters:
newMetadata- New metadata map- Returns:
- Syntax Object with updated metadata
-
withoutMeta
Removes all metadata from this Syntax Object- Returns:
- Syntax Object with empty metadata
-
unwrap
Unwraps a Syntax Object to get the underlying value. If the argument is not a Syntax object, return it unchanged (already unwrapped)- Type Parameters:
R- Expected type of value- Parameters:
x- Any Object, which may be a Syntax Object- Returns:
- The unwrapped value
-
unwrapAll
Recursively unwraps a Syntax object- Parameters:
maybeSyntax- Syntax Object to unwrap- Returns:
- Unwrapped object
-
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 classACell- Returns:
- Canonical version of Cell
-