Package convex.core.data
Class StringShort
- All Implemented Interfaces:
IValidated
,IWriteable
,Comparable<AString>
Class representing a short CVM string.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic int
Length of longest StringShort value that is embedded Basically max embedded length minus tag byte and 2-byte lengthstatic int
static int
Length of longest StringShort value in bytes.Fields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
StringShort(byte[] data)
protected
StringShort(byte[] data, int offset, int length)
protected
StringShort(Blob data)
-
Method Summary
Modifier and TypeMethodDescriptionbyte
byteAt(long index)
Gets a byte at the specified index.int
charAt(long index)
Gets the Unicode character at position i, or -1 if not validint
static StringShort
create(AArrayBlob b)
Creates a StringShort instance from a Blob of UTF-8 data.static StringShort
Creates a StringShort instance from a regular Java Stringint
encodeRaw(byte[] bs, int pos)
Encode the data of this String.int
encodeRawData(byte[] bs, int pos)
Encode the raw UTF-8 data of this String.boolean
Checks for equality with another object.boolean
equals(StringShort a)
int
Estimate the encoded data size for this Cell.int
Gets the number of Refs contained within this Cell.boolean
Returns true if this Cell is in a canonical representation for message writing.boolean
Returns true if this Cell represents a first class CVM Value.boolean
Determines if this Cell Represents an embedded object.static AString
read(long length, ByteBuffer bb)
Read a StringShort from a ByteBuffer.subSequence(long start, long end)
toBlob()
Converts this String to a Blob byte representation.Converts this Cell to its canonical version.void
Validates the local structure and invariants of this cell.protected void
writeToBuffer(ByteBuffer bb)
Methods inherited from class convex.core.data.AString
append, append, count, empty, encode, get, getElementRef, getTag, getType, hashCode, intAt, print, toCVMString, toString
Methods inherited from class convex.core.data.ACountable
isEmpty, size
Methods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, equals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, isCompletelyEncoded, mark, mark, updateRefs, validate, write
Methods inherited from class convex.core.data.AObject
attachEncoding, print, print
-
Field Details
-
MAX_EMBEDDED_STRING_LENGTH
public static final int MAX_EMBEDDED_STRING_LENGTHLength of longest StringShort value that is embedded Basically max embedded length minus tag byte and 2-byte length- See Also:
- Constant Field Values
-
MAX_LENGTH
public static final int MAX_LENGTHLength of longest StringShort value in bytes. Use Blob as base.- See Also:
- Constant Field Values
-
MAX_ENCODING_LENGTH
public static final int MAX_ENCODING_LENGTH
-
-
Constructor Details
-
StringShort
-
StringShort
protected StringShort(byte[] data) -
StringShort
protected StringShort(byte[] data, int offset, int length)
-
-
Method Details
-
create
Creates a StringShort instance from a regular Java String- Parameters:
string
- String to wrap as StringShort- Returns:
- StringShort instance, or null if String is of invalid size
-
create
Creates a StringShort instance from a Blob of UTF-8 data. Shares underlying array.- Parameters:
b
- Array Blob to convert to StringShort- Returns:
- StringShort instance
-
charAt
public int charAt(long index)Description copied from class:AString
Gets the Unicode character at position i, or -1 if not valid -
byteAt
public byte byteAt(long index)Description copied from class:AString
Gets a byte at the specified index. Returns -1 (0xff) if outside String. -
subSequence
- Specified by:
subSequence
in classAString
-
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
-
encodeRaw
public int encodeRaw(byte[] bs, int pos)Description copied from class:AString
Encode the data of this String. Assumes tag already written -
encodeRawData
public int encodeRawData(byte[] bs, int pos)Description copied from class:AString
Encode the raw UTF-8 data of this String. Assumes tag/length already written- Specified by:
encodeRawData
in classAString
- Parameters:
bs
- Byte array to encode topos
- Position in target array to write to- Returns:
- End position in array after encoding
-
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.
-
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 Cell represents a first class CVM Value. Sub-structural cells that are not themselves first class values 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:
isCVMValue
in classACell
- Returns:
- true if the object is a CVM Value, false otherwise
-
isEmbedded
public boolean isEmbedded()Description copied from class:ACell
Determines if this Cell Represents an embedded object. Embedded objects are encoded directly into the encoding of the containing Cell (avoiding the need for a hashed reference). Subclasses should override this if they have a cheap O(1) way to determine if they are embedded or otherwise.- Overrides:
isEmbedded
in classACell
- Returns:
- true if Cell is embedded, false otherwise
-
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
-
read
Read a StringShort from a ByteBuffer. Assumes tag and length already read and correct.- Parameters:
length
- Length in number of chars to readbb
- ByteBuffer to read from- Returns:
- AString instance
-
toBlob
Description copied from class:AString
Converts this String to a Blob byte representation. Must round trip all values. -
equals
Description copied from class:ACell
Checks for equality with another object. In general, data objects should be considered equal if they have the same canonical representation, i.e. an identical encoding with the same hash value. Subclasses SHOULD override this if offer have a more efficient equals implementation. MUST NOT require reads from Store. -
equals
-
compareTo
- Specified by:
compareTo
in interfaceComparable<AString>
- Specified by:
compareTo
in classAString
-
toCanonical
Description copied from class:ACell
Converts this Cell to its canonical version. Returns this Cell if already canonical, may be O(n) in size of value otherwise.- Specified by:
toCanonical
in classACell
- Returns:
- Canonical version of Cell
-
writeToBuffer
- Specified by:
writeToBuffer
in classAString
-