Package io.keikai.doc.collab.utils
Class Encodings
- java.lang.Object
-
- io.keikai.doc.collab.utils.Encodings
-
public class Encodings extends java.lang.ObjectWe use the first five bits in the info flag for determining the type of the struct. 0: GC 1: Item with Deleted content 2: Item with JSON content 3: Item with Binary content 4: Item with String content 5: Item with Embed content (for rich text content) 6: Item with Format content (a formatting marker for rich text content) 7: Item with Type
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidapplyUpdate(Doc ydoc, Uint8Array update)Apply a document update.static voidapplyUpdate(Doc ydoc, Uint8Array update, java.lang.Object transactionOrigin)Apply a document update.static voidapplyUpdateV2(Doc ydoc, Uint8Array update)Apply a document update.static voidapplyUpdateV2(Doc ydoc, Uint8Array update, java.lang.Object transactionOrigin, java.lang.Class<? extends UpdateDecoder> yDecoder)Apply a document update.static java.util.Map<java.lang.Integer,java.lang.Integer>decodeStateVector(Uint8Array decodedState)Decode state vector from a byte array.static Uint8ArrayencodeStateAsUpdate(Doc doc)Encode state as an update message.static Uint8ArrayencodeStateAsUpdate(Doc doc, Uint8Array encodedTargetStateVector)Encode state as an update message.static Uint8ArrayencodeStateAsUpdateV2(Doc doc)Encode state as an update message.static Uint8ArrayencodeStateAsUpdateV2(Doc doc, Uint8Array encodedTargetStateVector, UpdateEncoder encoder)Encode state as an update message.static Uint8ArrayencodeStateVector(Doc doc)Encode State as Uint8Array.static Uint8ArrayencodeStateVector(java.util.Map<java.lang.Integer,java.lang.Integer> doc)Encode State as Uint8Array.static Uint8ArrayencodeStateVectorV2(java.lang.Object doc, io.keikai.doc.collab.utils.DSEncoder encoder)Encode the state vector as a byte array.static java.util.Map<java.lang.Integer,StructRef>readClientsStructRefs(UpdateDecoder decoder, Doc doc)Read client struct references.static java.util.Map<java.lang.Integer,java.lang.Integer>readStateVector(DSDecoder decoder)Read state vector from the decoder.static voidreadUpdate(Decoder decoder, Doc ydoc, java.lang.Object transactionOrigin)Apply a document update.static voidreadUpdateV2(Decoder decoder, Doc ydoc, java.lang.Object transactionOrigin, UpdateDecoder structDecoder)Read and apply a document update.static voidwriteClientsStructs(UpdateEncoder encoder, StructStore store, java.util.Map<java.lang.Integer,java.lang.Integer> stateMap)Write client structs to the encoder.static voidwriteDocumentStateVector(io.keikai.doc.collab.utils.DSEncoder encoder, Doc doc)Write the document's state vector to the encoder.static voidwriteStateAsUpdate(UpdateEncoder encoder, Doc doc, java.util.Map<java.lang.Integer,java.lang.Integer> targetStateVector)Write all the document as a single update message.static voidwriteStateVector(io.keikai.doc.collab.utils.DSEncoder encoder, java.util.Map<java.lang.Integer,java.lang.Integer> sv)Write the state vector to the encoder.static voidwriteStructs(UpdateEncoder encoder, java.util.List<AbstractStruct> structs, int client, int clock)Write structs to the encoder.static voidwriteStructsFromTransaction(UpdateEncoder encoder, Transaction transaction)Write structs from a transaction.
-
-
-
Method Detail
-
writeStructs
public static void writeStructs(UpdateEncoder encoder, java.util.List<AbstractStruct> structs, int client, int clock)
Write structs to the encoder.- Parameters:
encoder- The encoder to write data to.structs- All structs by `client`.client- The client ID.clock- Write structs starting with `ID(client,clock)`.
-
writeClientsStructs
public static void writeClientsStructs(UpdateEncoder encoder, StructStore store, java.util.Map<java.lang.Integer,java.lang.Integer> stateMap)
Write client structs to the encoder.- Parameters:
encoder- The encoder to write data to.store- The StructStore containing the structs.stateMap- The state map.
-
readClientsStructRefs
public static java.util.Map<java.lang.Integer,StructRef> readClientsStructRefs(UpdateDecoder decoder, Doc doc)
Read client struct references.- Parameters:
decoder- The decoder object to read data from.doc- The document to which the structs belong.- Returns:
- A map of client IDs to struct references.
-
writeStructsFromTransaction
public static void writeStructsFromTransaction(UpdateEncoder encoder, Transaction transaction)
Write structs from a transaction.- Parameters:
encoder- The encoder to write data to.transaction- The transaction containing the structs.
-
readUpdateV2
public static void readUpdateV2(Decoder decoder, Doc ydoc, java.lang.Object transactionOrigin, UpdateDecoder structDecoder)
Read and apply a document update. This function has the same effect as `applyUpdate` but accepts a decoder.- Parameters:
decoder- The decoder object to read data from.ydoc- The document to apply the update to.transactionOrigin- The origin of the transaction, stored on `transaction.origin`.structDecoder- The struct decoder to use (either UpdateDecoderV1 or UpdateDecoderV2).
-
readUpdate
public static void readUpdate(Decoder decoder, Doc ydoc, java.lang.Object transactionOrigin)
Apply a document update. This function has the same effect as `readUpdate` but accepts a decoder.- Parameters:
decoder- The decoder object to read data from.ydoc- The document to apply the update to.transactionOrigin- The origin of the transaction, stored on `transaction.origin`.
-
applyUpdateV2
public static void applyUpdateV2(Doc ydoc, Uint8Array update)
Apply a document update. This function has the same effect as `readUpdate` but accepts an Uint8Array instead of a Decoder.- Parameters:
ydoc- The document to apply the update to.update- The update to apply.
-
applyUpdateV2
public static void applyUpdateV2(Doc ydoc, Uint8Array update, java.lang.Object transactionOrigin, java.lang.Class<? extends UpdateDecoder> yDecoder)
Apply a document update. This function has the same effect as `readUpdate` but accepts an Uint8Array instead of a Decoder.- Parameters:
ydoc- The document to apply the update to.update- The update to apply.transactionOrigin- The origin of the transaction, stored on `transaction.origin`.yDecoder- The decoder to use (either UpdateDecoderV1 or UpdateDecoderV2).
-
applyUpdate
public static void applyUpdate(Doc ydoc, Uint8Array update)
Apply a document update. This function has the same effect as `readUpdate` but accepts an Uint8Array instead of a Decoder.- Parameters:
ydoc- The document to apply the update to.update- The update to apply.
-
applyUpdate
public static void applyUpdate(Doc ydoc, Uint8Array update, java.lang.Object transactionOrigin)
Apply a document update. This function has the same effect as `readUpdate` but accepts an Uint8Array instead of a Decoder.- Parameters:
ydoc- The document to apply the update to.update- The update to apply.transactionOrigin- The origin of the transaction, stored on `transaction.origin`.
-
writeStateAsUpdate
public static void writeStateAsUpdate(UpdateEncoder encoder, Doc doc, java.util.Map<java.lang.Integer,java.lang.Integer> targetStateVector)
Write all the document as a single update message.- Parameters:
encoder- The encoder to write data to.doc- The document to write the update from.targetStateVector- The state of the target that receives the update. Leave empty to write all known structs.
-
encodeStateAsUpdateV2
public static Uint8Array encodeStateAsUpdateV2(Doc doc)
Encode state as an update message.- Parameters:
doc- The document to write the update from.- Returns:
- The encoded update.
-
encodeStateAsUpdateV2
public static Uint8Array encodeStateAsUpdateV2(Doc doc, Uint8Array encodedTargetStateVector, UpdateEncoder encoder)
Encode state as an update message.- Parameters:
doc- The document to write the update from.encodedTargetStateVector- The state of the target that receives the update.encoder- The encoder to use (either UpdateEncoderV1 or UpdateEncoderV2).- Returns:
- The encoded update.
-
encodeStateAsUpdate
public static Uint8Array encodeStateAsUpdate(Doc doc)
Encode state as an update message.- Parameters:
doc- The document to write the update from.- Returns:
- The encoded update.
-
encodeStateAsUpdate
public static Uint8Array encodeStateAsUpdate(Doc doc, Uint8Array encodedTargetStateVector)
Encode state as an update message.- Parameters:
doc- The document to write the update from.encodedTargetStateVector- The state of the target that receives the update.- Returns:
- The encoded update.
-
readStateVector
public static java.util.Map<java.lang.Integer,java.lang.Integer> readStateVector(DSDecoder decoder)
Read state vector from the decoder.- Parameters:
decoder- The decoder object to read data from.- Returns:
- A map of client IDs to the number of next expected clocks from those clients.
-
decodeStateVector
public static java.util.Map<java.lang.Integer,java.lang.Integer> decodeStateVector(Uint8Array decodedState)
Decode state vector from a byte array.- Parameters:
decodedState- The byte array containing the encoded state vector.- Returns:
- A map of client IDs to the number of next expected clocks from those clients.
-
writeStateVector
public static void writeStateVector(io.keikai.doc.collab.utils.DSEncoder encoder, java.util.Map<java.lang.Integer,java.lang.Integer> sv)Write the state vector to the encoder.- Parameters:
encoder- The encoder to write data to.sv- The state vector to write.
-
writeDocumentStateVector
public static void writeDocumentStateVector(io.keikai.doc.collab.utils.DSEncoder encoder, Doc doc)Write the document's state vector to the encoder.- Parameters:
encoder- The encoder to write data to.doc- The document whose state vector is being written.
-
encodeStateVectorV2
public static Uint8Array encodeStateVectorV2(java.lang.Object doc, io.keikai.doc.collab.utils.DSEncoder encoder)
Encode the state vector as a byte array.- Parameters:
doc- The document or state vector map.encoder- The encoder to use (either DSEncoderV1 or DSEncoderV2).- Returns:
- The encoded state vector as a byte array.
-
encodeStateVector
public static Uint8Array encodeStateVector(Doc doc)
Encode State as Uint8Array.- Parameters:
doc- The document- Returns:
- The encoded state vector as a byte array.
-
encodeStateVector
public static Uint8Array encodeStateVector(java.util.Map<java.lang.Integer,java.lang.Integer> doc)
Encode State as Uint8Array.- Parameters:
doc- The state vector map- Returns:
- The encoded state vector as a byte array.
-
-