Class Yrs
This class provides low-level access to the native yffi functions using Java's Foreign Function and Memory API (Project Panama).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final FunctionDescriptorFunctionDescriptor for the update observer callback.static final intChange type: elements were added.static final intChange type: elements were deleted.static final intChange type: elements were retained (no change).static final intKey change type: attribute was added.static final intKey change type: attribute was deleted.static final intKey change type: attribute was updated.static final byteTag constant for boolean values in YInput/YOutput.static final intYOutput tag for YXmlElement.static final intYOutput tag for YXmlFragment.static final intYOutput tag for YXmlText.static final StructLayoutLayout for YChunk formatting entry (embedded YOutput, not pointer).static final StructLayoutLayout for the YChunk struct.static final StructLayoutLayout for YDeltaOut struct.static final StructLayoutLayout for YEventChange struct.static final StructLayoutLayout for YEventKeyChange struct.static final StructLayoutLayout for the YInput struct (24 bytes).static final StructLayoutLayout for YMapEntry struct.static final StructLayoutLayout for the YOutput struct.static final byteYOutput tag for boolean content.static final byteYOutput tag for 64-bit floating-point content.static final byteYOutput tag for 64-bit integer content.static final byteYOutput tag for null content.static final byteYOutput tag for string content.static final FunctionDescriptorFunctionDescriptor for XML element/fragment observer callback.static final StructLayoutLayout for YXmlAttr struct.static final FunctionDescriptorFunctionDescriptor for XML text observer callback. -
Method Summary
Modifier and TypeMethodDescriptionstatic MemorySegmentcreateBinary(Arena arena, byte[] data) Copies a byte array to native memory in the given arena.static MemorySegmentcreateString(Arena arena, String str) Creates a native string from a Java string in the given arena.static MemorySegmentcreateYInputFromObject(Arena arena, Object value) Creates a YInput from a Java Object based on its type.static byte[]readAndFreeBinary(MemorySegment ptr, int len) Reads a native binary buffer and frees it.static StringReads a native string and frees it.static MemorySegmentyarray(MemorySegment doc, MemorySegment name) Gets or creates a YArray with the given name.static MemorySegmentyarrayGet(MemorySegment array, MemorySegment txn, int index) Gets a value from an array at the given index.static voidyarrayInsertRange(MemorySegment array, MemorySegment txn, int index, MemorySegment values, int valuesLen) Inserts values into an array at the given index.static intyarrayLen(MemorySegment array) Gets the length of a YArray.static voidyarrayRemoveRange(MemorySegment array, MemorySegment txn, int index, int len) Removes values from an array at the given range.static voidybinaryDestroy(MemorySegment ptr, int len) Frees a binary buffer allocated by yffi.static MemorySegmentybranchJson(MemorySegment branch, MemorySegment txn) Gets the JSON representation of a branch.static MemorySegmentGets a slice of the embedded YOutput value from a YChunk formatting entry.static StringReads the key from a YChunk formatting entry.static MemorySegmentychunkGetData(MemorySegment chunk) Gets the embedded YOutput data from a YChunk.static MemorySegmentychunkGetFmt(MemorySegment chunk) Gets the formatting entries pointer from a YChunk.static intychunkGetFmtLen(MemorySegment chunk) Gets the formatting entry count from a YChunk.static voidychunksDestroy(MemorySegment chunks, int len) Frees a YChunk array returned by ytextChunks.static voidydocDestroy(MemorySegment doc) Destroys a Y-CRDT document.static MemorySegmentydocGuid(MemorySegment doc) Gets the GUID of a document.static longydocId(MemorySegment doc) Gets the client ID of a document.static MemorySegmentydocNew()Creates a new Y-CRDT document.static MemorySegmentydocObserveUpdatesV1(MemorySegment doc, MemorySegment state, MemorySegment callback) Registers an observer for document updates (v1 encoding).static MemorySegmentCreates a read transaction on a document.static MemorySegmentydocWriteTransaction(MemorySegment doc, int originLen, MemorySegment origin) Creates a write transaction on a document.static voidyeventDeltaDestroy(MemorySegment delta, int len) Destroys an array of YEventChange structs.static voidyeventKeysDestroy(MemorySegment keys, int len) Destroys an array of YEventKeyChange structs.static MemorySegmentyinputBool(Arena arena, boolean value) Creates a YInput containing a boolean value.static MemorySegmentyinputFloat(Arena arena, double num) Creates a YInput containing a double value.static MemorySegmentyinputLong(Arena arena, long num) Creates a YInput containing a long value.static MemorySegmentCreates a YInput containing a map of attributes (for text formatting).static MemorySegmentyinputNull(Arena arena) Creates a YInput containing null (used for removing formatting attributes).static MemorySegmentyinputString(Arena arena, MemorySegment str) Creates a YInput containing a string value.static MemorySegmentyinputYdoc(Arena arena, MemorySegment docPtr) Creates a YInput containing a subdocument.static MemorySegmentymap(MemorySegment doc, MemorySegment name) Gets or creates a YMap with the given name.static voidymapEntryDestroy(MemorySegment entry) Destroys a map entry.static StringymapEntryReadKey(MemorySegment entry) Reads the key from a YMapEntry.static MemorySegmentymapGet(MemorySegment map, MemorySegment txn, MemorySegment key) Gets a value from a map by key.static voidymapInsert(MemorySegment map, MemorySegment txn, MemorySegment key, MemorySegment value) Inserts a value into a YMap.static MemorySegmentymapIter(MemorySegment map, MemorySegment txn) Creates an iterator over map entries.static voidymapIterDestroy(MemorySegment iter) Destroys a map iterator.static MemorySegmentymapIterNext(MemorySegment iter) Gets the next entry from the iterator.static intymapLen(MemorySegment map, MemorySegment txn) Gets the number of entries in a YMap.static voidymapRemove(MemorySegment map, MemorySegment txn, MemorySegment key) Removes a value from a YMap.static voidFrees a YOutput value.static byteyoutputGetTag(MemorySegment output) Reads the tag byte from a YOutput struct.static MemorySegmentReads a boolean from a YOutput value.static MemorySegmentReads a double from a YOutput value.static MemorySegmentReads a long from a YOutput value.static MemorySegmentReads a string from a YOutput value.static MemorySegmentReads a subdocument from a YOutput value.static MemorySegmentReads an XML element from a YOutput value.static MemorySegmentReads an XML text node from a YOutput value.static voidFrees a string allocated by yffi.static MemorySegmentytext(MemorySegment doc, MemorySegment name) Gets or creates a YText with the given name.static MemorySegmentytextChunks(MemorySegment txt, MemorySegment txn, MemorySegment lenOut) Gets formatted text chunks from a text node (YText or YXmlText).static voidytextDeltaDestroy(MemorySegment delta, int len) Destroys an array of YDeltaOut structs.static voidytextInsert(MemorySegment txt, MemorySegment txn, int index, MemorySegment value, MemorySegment attrs) Inserts text at the given index.static intytextLen(MemorySegment txt, MemorySegment txn) Gets the length of a YText.static voidytextRemoveRange(MemorySegment txt, MemorySegment txn, int index, int len) Removes text from the given range.static MemorySegmentytextString(MemorySegment txt, MemorySegment txn) Gets the string content of a YText.static byteytransactionApply(MemorySegment txn, MemorySegment diff, int diffLen) Applies an update diff to a transaction's document.static voidCommits and frees a transaction.static MemorySegmentytransactionStateDiffV1(MemorySegment txn, MemorySegment sv, int svLen, MemorySegment len) Gets the state diff from a transaction.static MemorySegmentGets the state vector from a transaction.static intytypeKind(MemorySegment branch) Gets the type kind of a branch.static voidyunobserve(MemorySegment subscription) Unsubscribes an observer.static voidyxmlattrDestroy(MemorySegment attr) Destroys an attribute.static voidDestroys an attribute iterator.static MemorySegmentGets the next attribute from the iterator.static StringReads the name from a YXmlAttr.static StringReads the value from a YXmlAttr.static MemorySegmentyxmlelemAttrIter(MemorySegment xml, MemorySegment txn) Creates an iterator over XML element attributes.static intyxmlelemChildLen(MemorySegment xml, MemorySegment txn) Gets the number of children in an XML element or fragment.static MemorySegmentyxmlelemEventDelta(MemorySegment event, MemorySegment lenOut) Gets the delta (child changes) from an XML element event.static MemorySegmentyxmlelemEventKeys(MemorySegment event, MemorySegment lenOut) Gets the key changes (attribute changes) from an XML element event.static MemorySegmentyxmlelemEventTarget(MemorySegment event) Gets the target branch of an XML element event.static MemorySegmentyxmlelemGet(MemorySegment xml, MemorySegment txn, int index) Gets a child from an XML element/fragment at the given index.static MemorySegmentyxmlelemGetAttr(MemorySegment xml, MemorySegment txn, MemorySegment name) Gets an attribute value from an XML element.static voidyxmlelemInsertAttr(MemorySegment xml, MemorySegment txn, MemorySegment name, MemorySegment value) Sets an attribute on an XML element.static MemorySegmentyxmlelemInsertElem(MemorySegment xml, MemorySegment txn, int index, MemorySegment name) Inserts a new XML element as a child at the given index.static MemorySegmentyxmlelemInsertText(MemorySegment xml, MemorySegment txn, int index) Inserts a new XML text node as a child at the given index.static MemorySegmentyxmlelemObserve(MemorySegment xml, MemorySegment state, MemorySegment callback) Registers an observer for XML element/fragment changes.static MemorySegmentGets the parent of an XML element or text node.static voidyxmlelemRemoveAttr(MemorySegment xml, MemorySegment txn, MemorySegment name) Removes an attribute from an XML element.static voidyxmlelemRemoveRange(MemorySegment xml, MemorySegment txn, int index, int len) Removes children from an XML element/fragment in a range.static MemorySegmentyxmlelemString(MemorySegment xml, MemorySegment txn) Gets the XML string representation of an element/fragment.static MemorySegmentyxmlelemTag(MemorySegment xml) Gets the tag name of an XML element.static MemorySegmentyxmlfragment(MemorySegment doc, MemorySegment name) Gets or creates a YXmlFragment with the given name.static MemorySegmentyxmltextEventDelta(MemorySegment event, MemorySegment lenOut) Gets the delta (text changes) from an XML text event.static MemorySegmentyxmltextEventTarget(MemorySegment event) Gets the target branch of an XML text event.static voidyxmltextFormat(MemorySegment txt, MemorySegment txn, int index, int len, MemorySegment attrs) Applies formatting to a range of text in an XML text node.static voidyxmltextInsert(MemorySegment txt, MemorySegment txn, int index, MemorySegment str, MemorySegment attrs) Inserts text into an XML text node at the given index.static intyxmltextLen(MemorySegment txt, MemorySegment txn) Gets the length of an XML text node.static MemorySegmentyxmltextObserve(MemorySegment xml, MemorySegment state, MemorySegment callback) Registers an observer for XML text changes.static voidyxmltextRemoveRange(MemorySegment txt, MemorySegment txn, int index, int len) Removes text from an XML text node at the given range.static MemorySegmentyxmltextString(MemorySegment txt, MemorySegment txn) Gets the string content of an XML text node.
-
Field Details
-
Y_JSON_BOOL
public static final byte Y_JSON_BOOLTag constant for boolean values in YInput/YOutput.- See Also:
-
YINPUT_LAYOUT
Layout for the YInput struct (24 bytes). The struct is: tag (1) + padding (3) + len (4) + union value (16 for YMapInputData).The native YInput struct is 24 bytes total. The union can hold various types including YMapInputData (two pointers = 16 bytes). We construct these structs manually to avoid ARM64 ABI issues with struct-by-value returns.
-
YMAP_ENTRY_LAYOUT
Layout for YMapEntry struct. The struct is: const char *key (8 bytes) + const struct YOutput *value (8 bytes) -
Y_XML_ELEM
public static final int Y_XML_ELEMYOutput tag for YXmlElement.- See Also:
-
Y_XML_TEXT
public static final int Y_XML_TEXTYOutput tag for YXmlText.- See Also:
-
Y_XML_FRAG
public static final int Y_XML_FRAGYOutput tag for YXmlFragment.- See Also:
-
UPDATE_CALLBACK_DESCRIPTOR
FunctionDescriptor for the update observer callback. Signature: void callback(void* state, uint32_t len, const char* data) -
Y_EVENT_CHANGE_ADD
public static final int Y_EVENT_CHANGE_ADDChange type: elements were added.- See Also:
-
Y_EVENT_CHANGE_DELETE
public static final int Y_EVENT_CHANGE_DELETEChange type: elements were deleted.- See Also:
-
Y_EVENT_CHANGE_RETAIN
public static final int Y_EVENT_CHANGE_RETAINChange type: elements were retained (no change).- See Also:
-
Y_EVENT_KEY_CHANGE_ADD
public static final int Y_EVENT_KEY_CHANGE_ADDKey change type: attribute was added.- See Also:
-
Y_EVENT_KEY_CHANGE_DELETE
public static final int Y_EVENT_KEY_CHANGE_DELETEKey change type: attribute was deleted.- See Also:
-
Y_EVENT_KEY_CHANGE_UPDATE
public static final int Y_EVENT_KEY_CHANGE_UPDATEKey change type: attribute was updated.- See Also:
-
YXML_CALLBACK_DESCRIPTOR
FunctionDescriptor for XML element/fragment observer callback. Signature: void callback(void* state, const YXmlEvent* event) -
YXMLTEXT_CALLBACK_DESCRIPTOR
FunctionDescriptor for XML text observer callback. Signature: void callback(void* state, const YXmlTextEvent* event) -
YEVENT_CHANGE_LAYOUT
Layout for YEventChange struct. struct YEventChange { uint8_t tag; uint32_t len; const YOutput *values; } -
YEVENT_KEY_CHANGE_LAYOUT
Layout for YEventKeyChange struct. struct YEventKeyChange { const char *key; char tag; const YOutput *old_value; const YOutput *new_value; } -
YDELTA_OUT_LAYOUT
Layout for YDeltaOut struct. struct YDeltaOut { uint8_t tag; uint32_t len; uint32_t attributes_len; YDeltaAttr *attributes; YOutput *insert; } -
YXMLATTR_LAYOUT
Layout for YXmlAttr struct. The struct is: const char *name (8 bytes) + const char *value (8 bytes) -
YOUTPUT_LAYOUT
Layout for the YOutput struct. struct YOutput { int8_t tag; uint32_t len; union value (16 bytes) } -
YOUTPUT_TAG_STRING
public static final byte YOUTPUT_TAG_STRINGYOutput tag for string content.- See Also:
-
YOUTPUT_TAG_INT
public static final byte YOUTPUT_TAG_INTYOutput tag for 64-bit integer content.- See Also:
-
YOUTPUT_TAG_FLOAT
public static final byte YOUTPUT_TAG_FLOATYOutput tag for 64-bit floating-point content.- See Also:
-
YOUTPUT_TAG_BOOL
public static final byte YOUTPUT_TAG_BOOLYOutput tag for boolean content.- See Also:
-
YOUTPUT_TAG_NULL
public static final byte YOUTPUT_TAG_NULLYOutput tag for null content.- See Also:
-
YCHUNK_FMT_ENTRY_LAYOUT
Layout for YChunk formatting entry (embedded YOutput, not pointer). struct YChunkFmtEntry { const char *key; struct YOutput value; }Note: Different from YMAP_ENTRY_LAYOUT which has pointer to YOutput. This layout has embedded YOutput, so total size is 8 + 24 = 32 bytes.
-
YCHUNK_LAYOUT
Layout for the YChunk struct. struct YChunk { YOutput data; uint32_t fmt_len; YMapEntry *fmt; }
-
-
Method Details
-
ydocNew
Creates a new Y-CRDT document.- Returns:
- pointer to the new document
-
ydocDestroy
Destroys a Y-CRDT document.- Parameters:
doc- pointer to the document
-
ydocId
Gets the client ID of a document.- Parameters:
doc- pointer to the document- Returns:
- the client ID
-
ydocGuid
Gets the GUID of a document.- Parameters:
doc- pointer to the document- Returns:
- pointer to the GUID string (must be freed with ystringDestroy)
-
ydocReadTransaction
Creates a read transaction on a document.- Parameters:
doc- pointer to the document- Returns:
- pointer to the transaction
-
ydocWriteTransaction
public static MemorySegment ydocWriteTransaction(MemorySegment doc, int originLen, MemorySegment origin) Creates a write transaction on a document.- Parameters:
doc- pointer to the documentoriginLen- length of the origin stringorigin- pointer to the origin string (can be NULL)- Returns:
- pointer to the transaction
-
ytransactionCommit
Commits and frees a transaction.- Parameters:
txn- pointer to the transaction
-
ytransactionStateVectorV1
Gets the state vector from a transaction.- Parameters:
txn- pointer to the transactionlen- pointer to store the length- Returns:
- pointer to the state vector (must be freed with ybinaryDestroy)
-
ytransactionStateDiffV1
public static MemorySegment ytransactionStateDiffV1(MemorySegment txn, MemorySegment sv, int svLen, MemorySegment len) Gets the state diff from a transaction.- Parameters:
txn- pointer to the transactionsv- pointer to the state vectorsvLen- length of the state vectorlen- pointer to store the result length- Returns:
- pointer to the diff (must be freed with ybinaryDestroy)
-
ytransactionApply
Applies an update diff to a transaction's document.- Parameters:
txn- pointer to the transactiondiff- pointer to the update diffdiffLen- length of the diff- Returns:
- 0 on success, error code on failure
-
ytext
Gets or creates a YText with the given name.- Parameters:
doc- pointer to the documentname- pointer to the name string- Returns:
- pointer to the text branch
-
ytextLen
Gets the length of a YText.- Parameters:
txt- pointer to the text branchtxn- pointer to the transaction- Returns:
- the length
-
ytextString
Gets the string content of a YText.- Parameters:
txt- pointer to the text branchtxn- pointer to the transaction- Returns:
- pointer to the string (must be freed with ystringDestroy)
-
ytextInsert
public static void ytextInsert(MemorySegment txt, MemorySegment txn, int index, MemorySegment value, MemorySegment attrs) Inserts text at the given index.- Parameters:
txt- pointer to the text branchtxn- pointer to the transactionindex- the index to insert atvalue- pointer to the value stringattrs- pointer to the attributes (can be NULL)
-
ytextRemoveRange
Removes text from the given range.- Parameters:
txt- pointer to the text branchtxn- pointer to the transactionindex- the start indexlen- the length to remove
-
yarray
Gets or creates a YArray with the given name.- Parameters:
doc- pointer to the documentname- pointer to the name string- Returns:
- pointer to the array branch
-
yarrayLen
Gets the length of a YArray.- Parameters:
array- pointer to the array branch- Returns:
- the length
-
yarrayInsertRange
public static void yarrayInsertRange(MemorySegment array, MemorySegment txn, int index, MemorySegment values, int valuesLen) Inserts values into an array at the given index.- Parameters:
array- pointer to the array branchtxn- pointer to the transactionindex- the index to insert atvalues- pointer to the values arrayvaluesLen- the number of values
-
yarrayRemoveRange
Removes values from an array at the given range.- Parameters:
array- pointer to the array branchtxn- pointer to the transactionindex- the start indexlen- the number of values to remove
-
ymap
Gets or creates a YMap with the given name.- Parameters:
doc- pointer to the documentname- pointer to the name string- Returns:
- pointer to the map branch
-
ymapLen
Gets the number of entries in a YMap.- Parameters:
map- pointer to the map branchtxn- pointer to the transaction- Returns:
- the number of entries
-
ymapInsert
public static void ymapInsert(MemorySegment map, MemorySegment txn, MemorySegment key, MemorySegment value) Inserts a value into a YMap.- Parameters:
map- pointer to the map branchtxn- pointer to the transactionkey- pointer to the key stringvalue- pointer to the YInput value
-
ymapRemove
Removes a value from a YMap.- Parameters:
map- pointer to the map branchtxn- pointer to the transactionkey- pointer to the key string
-
yxmlfragment
Gets or creates a YXmlFragment with the given name.- Parameters:
doc- pointer to the documentname- pointer to the name string- Returns:
- pointer to the xml fragment branch
-
ystringDestroy
Frees a string allocated by yffi.- Parameters:
str- pointer to the string
-
ybinaryDestroy
Frees a binary buffer allocated by yffi.- Parameters:
ptr- pointer to the bufferlen- length of the buffer
-
createString
Creates a native string from a Java string in the given arena.- Parameters:
arena- the arena to allocate instr- the Java string- Returns:
- pointer to the native string
-
readAndFreeString
Reads a native string and frees it.- Parameters:
ptr- pointer to the native string- Returns:
- the Java string
-
readAndFreeBinary
Reads a native binary buffer and frees it.- Parameters:
ptr- pointer to the bufferlen- length of the buffer- Returns:
- the byte array
-
createBinary
Copies a byte array to native memory in the given arena.- Parameters:
arena- the arena to allocate indata- the byte array- Returns:
- pointer to the native buffer
-
yinputString
Creates a YInput containing a string value.This constructs the YInput struct manually in Java to avoid ARM64 ABI issues with the native yinput_string function, which returns a 24-byte struct via sret.
- Parameters:
arena- the arena to allocate the struct instr- pointer to the null-terminated string- Returns:
- the YInput struct as a MemorySegment
-
yinputFloat
Creates a YInput containing a double value.This constructs the YInput struct manually in Java to avoid ARM64 ABI issues with the native yinput_float function.
- Parameters:
arena- the arena to allocate the struct innum- the double value- Returns:
- the YInput struct as a MemorySegment
-
yinputLong
Creates a YInput containing a long value.This constructs the YInput struct manually in Java to avoid ARM64 ABI issues with the native yinput_long function.
- Parameters:
arena- the arena to allocate the struct innum- the long value- Returns:
- the YInput struct as a MemorySegment
-
yinputYdoc
Creates a YInput containing a subdocument.This constructs the YInput struct manually in Java to avoid ARM64 ABI issues with the native yinput_ydoc function.
- Parameters:
arena- the arena to allocate the struct indocPtr- pointer to the YDoc- Returns:
- the YInput struct as a MemorySegment
-
yinputBool
Creates a YInput containing a boolean value.- Parameters:
arena- the arena to allocate the struct invalue- the boolean value- Returns:
- the YInput struct as a MemorySegment
-
yinputNull
Creates a YInput containing null (used for removing formatting attributes).- Parameters:
arena- the arena to allocate the struct in- Returns:
- the YInput struct as a MemorySegment
-
yinputMap
Creates a YInput containing a map of attributes (for text formatting).This is used to pass formatting attributes to yxmltext_insert and yxmltext_format. The map is converted to the native YMapInputData format with separate arrays for keys and values.
- Parameters:
arena- the arena to allocate all memory inattributes- the attributes map (can be null or empty)- Returns:
- pointer to the YInput struct, or NULL segment if attributes is null/empty
-
createYInputFromObject
Creates a YInput from a Java Object based on its type.Supported inputs:
null,Boolean,String,Double/Float, and any otherNumber. A non-primitive, non-null, non-Number object falls back to itsObject.toString()representation.- Parameters:
arena- the arena to allocate invalue- the Java value- Returns:
- the YInput struct
-
yarrayGet
Gets a value from an array at the given index.- Parameters:
array- pointer to the array branchtxn- pointer to the transactionindex- the index- Returns:
- pointer to the YOutput (must be freed with youtputDestroy)
-
youtputDestroy
Frees a YOutput value.- Parameters:
val- pointer to the YOutput
-
youtputReadString
Reads a string from a YOutput value.- Parameters:
val- pointer to the YOutput- Returns:
- pointer to the string (must be freed with ystringDestroy), or null if not a string
-
youtputReadFloat
Reads a double from a YOutput value.- Parameters:
val- pointer to the YOutput- Returns:
- pointer to the double, or null if not a double
-
youtputReadLong
Reads a long from a YOutput value.- Parameters:
val- pointer to the YOutput- Returns:
- pointer to the long, or null if not a long
-
youtputReadYdoc
Reads a subdocument from a YOutput value.- Parameters:
val- pointer to the YOutput- Returns:
- pointer to the YDoc, or null if not a subdocument
-
youtputReadBool
Reads a boolean from a YOutput value.- Parameters:
val- pointer to the YOutput- Returns:
- pointer to the boolean (uint8_t), or null if not a boolean
-
ymapIter
Creates an iterator over map entries.- Parameters:
map- pointer to the map branchtxn- pointer to the transaction- Returns:
- pointer to the iterator
-
ymapIterDestroy
Destroys a map iterator.- Parameters:
iter- pointer to the iterator
-
ymapIterNext
Gets the next entry from the iterator.- Parameters:
iter- pointer to the iterator- Returns:
- pointer to the entry, or null if no more entries
-
ymapEntryDestroy
Destroys a map entry.- Parameters:
entry- pointer to the entry
-
ymapEntryReadKey
Reads the key from a YMapEntry.- Parameters:
entry- pointer to the entry- Returns:
- the key string
-
ymapGet
Gets a value from a map by key.- Parameters:
map- pointer to the map branchtxn- pointer to the transactionkey- pointer to the key string- Returns:
- pointer to the YOutput (must be freed with youtputDestroy), or null if not found
-
ytypeKind
Gets the type kind of a branch.- Parameters:
branch- pointer to the branch- Returns:
- the type kind (Y_XML_ELEM, Y_XML_TEXT, Y_XML_FRAG, etc.)
-
yxmlelemParent
Gets the parent of an XML element or text node.- Parameters:
xml- pointer to the xml branch- Returns:
- pointer to the parent branch, or null if root-level
-
ybranchJson
Gets the JSON representation of a branch.- Parameters:
branch- pointer to the branchtxn- pointer to the transaction- Returns:
- pointer to the JSON string (must be freed with ystringDestroy)
-
ydocObserveUpdatesV1
public static MemorySegment ydocObserveUpdatesV1(MemorySegment doc, MemorySegment state, MemorySegment callback) Registers an observer for document updates (v1 encoding).- Parameters:
doc- pointer to the documentstate- opaque state pointer passed to callbackcallback- function pointer for the callback (created via Linker.upcallStub)- Returns:
- pointer to the subscription (must be freed with yunobserve)
-
yunobserve
Unsubscribes an observer.- Parameters:
subscription- pointer to the subscription
-
yxmlelemObserve
public static MemorySegment yxmlelemObserve(MemorySegment xml, MemorySegment state, MemorySegment callback) Registers an observer for XML element/fragment changes.- Parameters:
xml- pointer to the xml branchstate- opaque state pointer passed to callbackcallback- function pointer for the callback- Returns:
- pointer to the subscription
-
yxmltextObserve
public static MemorySegment yxmltextObserve(MemorySegment xml, MemorySegment state, MemorySegment callback) Registers an observer for XML text changes.- Parameters:
xml- pointer to the xml text branchstate- opaque state pointer passed to callbackcallback- function pointer for the callback- Returns:
- pointer to the subscription
-
yxmlelemEventTarget
Gets the target branch of an XML element event.- Parameters:
event- pointer to the event- Returns:
- pointer to the target branch
-
yxmltextEventTarget
Gets the target branch of an XML text event.- Parameters:
event- pointer to the event- Returns:
- pointer to the target branch
-
yxmlelemEventDelta
Gets the delta (child changes) from an XML element event.- Parameters:
event- pointer to the eventlenOut- pointer to uint32_t to receive length- Returns:
- pointer to array of YEventChange structs
-
yxmlelemEventKeys
Gets the key changes (attribute changes) from an XML element event.- Parameters:
event- pointer to the eventlenOut- pointer to uint32_t to receive length- Returns:
- pointer to array of YEventKeyChange structs
-
yxmltextEventDelta
Gets the delta (text changes) from an XML text event.- Parameters:
event- pointer to the eventlenOut- pointer to uint32_t to receive length- Returns:
- pointer to array of YDeltaOut structs
-
yeventDeltaDestroy
Destroys an array of YEventChange structs.- Parameters:
delta- pointer to the arraylen- length of the array
-
yeventKeysDestroy
Destroys an array of YEventKeyChange structs.- Parameters:
keys- pointer to the arraylen- length of the array
-
ytextDeltaDestroy
Destroys an array of YDeltaOut structs.- Parameters:
delta- pointer to the arraylen- length of the array
-
yxmlelemChildLen
Gets the number of children in an XML element or fragment.- Parameters:
xml- pointer to the xml branchtxn- pointer to the transaction- Returns:
- the number of children
-
yxmlelemTag
Gets the tag name of an XML element.- Parameters:
xml- pointer to the xml element branch- Returns:
- pointer to the tag string (must be freed with ystringDestroy)
-
yxmlelemInsertElem
public static MemorySegment yxmlelemInsertElem(MemorySegment xml, MemorySegment txn, int index, MemorySegment name) Inserts a new XML element as a child at the given index.- Parameters:
xml- pointer to the xml element/fragment branchtxn- pointer to the transactionindex- the index to insert atname- pointer to the tag name string- Returns:
- pointer to the new element branch
-
yxmlelemInsertText
Inserts a new XML text node as a child at the given index.- Parameters:
xml- pointer to the xml element/fragment branchtxn- pointer to the transactionindex- the index to insert at- Returns:
- pointer to the new text branch
-
yxmlelemRemoveRange
Removes children from an XML element/fragment in a range.- Parameters:
xml- pointer to the xml branchtxn- pointer to the transactionindex- the start indexlen- the number of children to remove
-
yxmlelemGet
Gets a child from an XML element/fragment at the given index.- Parameters:
xml- pointer to the xml branchtxn- pointer to the transactionindex- the index- Returns:
- pointer to YOutput (must be freed with youtputDestroy)
-
yxmlelemString
Gets the XML string representation of an element/fragment.- Parameters:
xml- pointer to the xml branchtxn- pointer to the transaction- Returns:
- pointer to the XML string (must be freed with ystringDestroy)
-
yxmlelemInsertAttr
public static void yxmlelemInsertAttr(MemorySegment xml, MemorySegment txn, MemorySegment name, MemorySegment value) Sets an attribute on an XML element.- Parameters:
xml- pointer to the xml element branchtxn- pointer to the transactionname- pointer to the attribute name stringvalue- pointer to the attribute value string
-
yxmlelemRemoveAttr
Removes an attribute from an XML element.- Parameters:
xml- pointer to the xml element branchtxn- pointer to the transactionname- pointer to the attribute name string
-
yxmlelemGetAttr
public static MemorySegment yxmlelemGetAttr(MemorySegment xml, MemorySegment txn, MemorySegment name) Gets an attribute value from an XML element.- Parameters:
xml- pointer to the xml element branchtxn- pointer to the transactionname- pointer to the attribute name string- Returns:
- pointer to the value string (must be freed with ystringDestroy), or null
-
yxmlelemAttrIter
Creates an iterator over XML element attributes.- Parameters:
xml- pointer to the xml element branchtxn- pointer to the transaction- Returns:
- pointer to the iterator
-
yxmlattrIterNext
Gets the next attribute from the iterator.- Parameters:
iter- pointer to the iterator- Returns:
- pointer to the attribute, or null if no more attributes
-
yxmlattrIterDestroy
Destroys an attribute iterator.- Parameters:
iter- pointer to the iterator
-
yxmlattrDestroy
Destroys an attribute.- Parameters:
attr- pointer to the attribute
-
yxmlattrReadName
Reads the name from a YXmlAttr.- Parameters:
attr- pointer to the attribute- Returns:
- the name string
-
yxmlattrReadValue
Reads the value from a YXmlAttr.- Parameters:
attr- pointer to the attribute- Returns:
- the value string
-
yxmltextLen
Gets the length of an XML text node.- Parameters:
txt- pointer to the xml text branchtxn- pointer to the transaction- Returns:
- the length
-
yxmltextString
Gets the string content of an XML text node.- Parameters:
txt- pointer to the xml text branchtxn- pointer to the transaction- Returns:
- pointer to the string (must be freed with ystringDestroy)
-
yxmltextInsert
public static void yxmltextInsert(MemorySegment txt, MemorySegment txn, int index, MemorySegment str, MemorySegment attrs) Inserts text into an XML text node at the given index.- Parameters:
txt- pointer to the xml text branchtxn- pointer to the transactionindex- the index to insert atstr- pointer to the string to insertattrs- pointer to attributes (can be NULL)
-
yxmltextRemoveRange
Removes text from an XML text node at the given range.- Parameters:
txt- pointer to the xml text branchtxn- pointer to the transactionindex- the start indexlen- the length to remove
-
yxmltextFormat
public static void yxmltextFormat(MemorySegment txt, MemorySegment txn, int index, int len, MemorySegment attrs) Applies formatting to a range of text in an XML text node.- Parameters:
txt- pointer to the xml text branchtxn- pointer to the transactionindex- the start indexlen- the length to formatattrs- pointer to the formatting attributes
-
youtputReadYxmlelem
Reads an XML element from a YOutput value.- Parameters:
val- pointer to the YOutput- Returns:
- pointer to the element branch, or null if not an element
-
youtputReadYxmltext
Reads an XML text node from a YOutput value.- Parameters:
val- pointer to the YOutput- Returns:
- pointer to the text branch, or null if not a text node
-
youtputGetTag
Reads the tag byte from a YOutput struct.- Parameters:
output- the YOutput memory segment- Returns:
- the tag byte indicating the content type
-
ytextChunks
Gets formatted text chunks from a text node (YText or YXmlText).- Parameters:
txt- pointer to the text branchtxn- pointer to the transactionlenOut- pointer to uint32_t to receive chunk count- Returns:
- pointer to YChunk array (must be freed with ychunksDestroy)
-
ychunksDestroy
Frees a YChunk array returned by ytextChunks.- Parameters:
chunks- pointer to the chunks arraylen- number of chunks
-
ychunkGetData
Gets the embedded YOutput data from a YChunk.- Parameters:
chunk- pointer to the YChunk- Returns:
- memory segment pointing to the embedded YOutput data
-
ychunkGetFmtLen
Gets the formatting entry count from a YChunk.- Parameters:
chunk- pointer to the YChunk- Returns:
- the number of formatting entries
-
ychunkGetFmt
Gets the formatting entries pointer from a YChunk.- Parameters:
chunk- pointer to the YChunk- Returns:
- pointer to the formatting entries array, or NULL if none
-
ychunkFmtEntryReadKey
Reads the key from a YChunk formatting entry.- Parameters:
entry- pointer to the formatting entry- Returns:
- the key string
-
ychunkFmtEntryGetValue
Gets a slice of the embedded YOutput value from a YChunk formatting entry.- Parameters:
entry- pointer to the formatting entry- Returns:
- memory segment pointing to the embedded YOutput
-