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 Syntax
Wraps a value as a Syntax Object with empty metadata.static Syntax
Wraps a value as a Syntax Object, adding the given new metadatastatic Syntax
createUnchecked(ACell value, AHashMap<ACell,ACell> meta)
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 byteint
Estimate 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.int
Gets the number of Refs contained within this Cell.getStart()
byte
getTag()
Gets the tag byte for this cell.getType()
Gets the most specific known runtime Type for this Cell.<R> R
getValue()
Gets the value datum from this Syntax Objectboolean
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.static Syntax
Merge metadata into a Cell, after wrapping as a Syntax ObjectMerges metadata into this syntax object, overriding existing metadatastatic Syntax
Wraps a value as a Syntax Object with empty metadata.static Syntax
Create a Syntax Object with the given value.void
print(StringBuilder sb)
Prints this Object to a readable String Representationstatic Syntax
read(ByteBuffer bb)
Converts this Cell to its canonical version.toString()
Returns the String representation of this Cell.static <R> R
Unwraps 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.void
validate()
Validates the complete structure of this object.void
Validates 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, mark, mark, write
Methods inherited from class convex.core.data.AObject
attachEncoding, print
-
Field Details
-
EMPTY
-
-
Method Details
-
getType
Description copied from class:ACell
Gets 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: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).- Specified by:
isCanonical
in classACell
- Returns:
- true if the object is in canonical format, false otherwise
-
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- Specified by:
isCVMValue
in 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: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
-
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 -
print
Description copied from class:AObject
Prints this Object to a readable String Representation -
toString
Description copied from class:ACell
Returns 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: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.- Specified by:
validateCell
in classACell
- Throws:
InvalidDataException
- If the Cell is invalid
-
validate
Description copied from interface:IValidated
Validates 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:
validate
in interfaceIValidated
- Overrides:
validate
in classACell
- Throws:
InvalidDataException
- If the data Valie is invalid in any way
-
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.
-
getRefCount
public int getRefCount()Description copied from class:ACell
Gets 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:
getRefCount
in classACell
- Returns:
- The number of Refs in this Cell
-
getRef
Description copied from class:ACell
Gets a numbered child Ref from within this Cell. -
updateRefs
Description copied from class:ACell
Updates 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:
updateRefs
in 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: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 classACell
- Returns:
- Canonical version of Cell
-