Package convex.core.data
Class StringSlice
java.lang.Object
- All Implemented Interfaces:
IValidated,IWriteable,Comparable<ABlobLike<?>>
AString subclass representing a view some String data. Not canonical!
-
Field Summary
Fields inherited from class convex.core.data.ACell
cachedRef, memorySize -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbytebyteAt(long i) Gets a byte at the specified index.intstatic AStringcreate(StringTree source, long start, long len) 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) Encode the data of this String.booleanChecks for equality between two strings.booleanequalsBytes(ABlob b) Compare the byte content of this BlobLike to a Blob valueintEstimate the encoded data size for this Cell.intGets the number of Refs contained within this Cell.booleanReturns true if this Cell is in a canonical representation.final booleanReturns true if this cell is a first class CVM Value allowable in the CVM state Sub-structural cells that are not themselves first class values should return false Records and types that are not permissible on the CVM should return false.longConverts this BlobLike to the corresponding long value.protected voidprintEscaped(BlobBuilder sb, long start, long end) Prints this string as escaped UTF-8slice(long start, long end) Gets a slice of this string, or null if not a valid slicetoBlob()Converts this String to an equivalent Blob representation.Converts this Cell to a canonical version.voidValidates the local structure and invariants of this cell.intwriteRawData(byte[] bs, int pos) Write the raw UTF-8 data of this String to a byte array.Methods inherited from class convex.core.data.AString
append, append, charAt, count, empty, equals, get, getBytes, getElementRef, getTag, getType, hashCode, hexMatch, intAt, print, split, toCVMString, toStringMethods inherited from class convex.core.data.ABlobLike
appendHex, byteAtUnchecked, getBytes, getHexDigit, hexEquals, hexLength, hexMatch, isDataValue, toFlatBlob, toHexString, toHexStringMethods inherited from class convex.core.data.ACountable
isEmpty, size, sliceMethods inherited from class convex.core.data.ACell
attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createEncoding, createRef, equals, genericEquals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getMemorySize, getRef, getRef, isEmbedded, updateRefs, validateMethods inherited from class convex.core.data.AObject
attachEncoding, print, print
-
Constructor Details
-
StringSlice
-
-
Method Details
-
create
-
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- Overrides:
encodein classAString- 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:AStringEncode the data of this String. Assumes tag already written -
writeRawData
public int writeRawData(byte[] bs, int pos) Description copied from class:AStringWrite the raw UTF-8 data of this String to a byte array.- Specified by:
writeRawDatain classAString- Parameters:
bs- Destination byte arraypos- Position in target array to write to- Returns:
- End position in array after writing
-
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 highly likely to contain the entire object when encoded, including the tag byte. Should not traverse soft Refs, i.e. must be usable on arbitrary partial data structures- Returns:
- The estimated size for the binary representation of this object.
-
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
-
isCVMValue
public final boolean isCVMValue()Description copied from class:ACellReturns true if this cell is a first class CVM Value allowable in the CVM state Sub-structural cells that are not themselves first class values should return false Records and types that are not permissible on the CVM should return false. Pretty much everything else should return true. Note: 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
-
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 classACell- Returns:
- The number of Refs in this Cell
-
byteAt
-
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 classAString- Returns:
- Canonical version of Cell
-
toBlob
-
compareTo
-
slice
-
printEscaped
Description copied from class:AStringPrints this string as escaped UTF-8- Specified by:
printEscapedin classAString- Parameters:
sb-
-
equals
-
equalsBytes
Description copied from class:ABlobLikeCompare the byte content of this BlobLike to a Blob value- Specified by:
equalsBytesin classABlobLike<CVMChar>- Parameters:
b- Blob value to compare with- Returns:
- `true` if byte contents are exactly equal, `false` otherwise
-
longValue
public long longValue()Description copied from class:ABlobLikeConverts this BlobLike to the corresponding long value. Assumes big-endian format, as if the entire blob is interpreted as an unsigned big integer. Higher bytes outside the Long range will be ignored, i.e. the lowest 64 bits are taken
-