Package convex.core.data.prim
Class CVMByte
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.data.prim.APrimitive
convex.core.data.prim.CVMByte
- All Implemented Interfaces:
INumeric,IValidated,IWriteable
Class for CVM Byte instances.
Bytes are unsigned 8-bit integers which upcast to long for numerical operations.
-
Field Summary
FieldsFields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY -
Method Summary
Modifier and TypeMethodDescriptionbytestatic CVMBytecreate(long value) doubleintencode(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.intEstimate the encoded data size for this Cell.bytegetTag()Gets the tag byte for this cell.getType()Gets the most specific known runtime Type for this Cell.longUnsigned long value representing this ByteClass<?>Gets the numeric type that should be used as for calculationsbooleanprint(BlobBuilder bb, long limit) Prints this Object to a readable String Representation.signum()Gets the signum of this numerical value.toCVMString(long limit) Returns the CVM String representation of this Cell.toDouble()toLong()voidValidates the local structure and invariants of this cell.Methods inherited from class convex.core.data.prim.APrimitive
calcMemorySize, createRef, getRefCount, isCanonical, isCVMValue, isEmbedded, toCanonicalMethods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, createAnnounced, createEncoding, createPersisted, createPersisted, equals, equals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, hashCode, isCompletelyEncoded, mark, mark, toString, updateRefs, validate, writeMethods inherited from class convex.core.data.AObject
attachEncoding, print, print
-
Field Details
-
ZERO
-
ONE
-
MAX_ENCODING_LENGTH
public static final int MAX_ENCODING_LENGTH- See Also:
-
-
Method Details
-
create
-
getType
Description copied from class:ACellGets the most specific known runtime Type for this Cell. -
longValue
public long longValue()Unsigned long value representing this Byte- Specified by:
longValuein classAPrimitive- Returns:
- long value representing primitive
-
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.
-
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
-
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. -
numericType
Description copied from interface:INumericGets the numeric type that should be used as for calculations- Specified by:
numericTypein interfaceINumeric- Returns:
- Double.class or Long.class, or null if not a numeric type
-
doubleValue
public double doubleValue()- Specified by:
doubleValuein interfaceINumeric- Specified by:
doubleValuein classAPrimitive- Returns:
- double value representing primitive
-
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 -
toLong
-
toDouble
-
signum
Description copied from interface:INumericGets the signum of this numerical value. Will be -1, 0 or 1 for Longs, -1.0, 0.0 , 1.0 or ##NaN for Doubles. -
byteValue
public byte byteValue() -
toStandardNumber
- Specified by:
toStandardNumberin interfaceINumeric
-
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
-