Class Encodings

java.lang.Object
io.keikai.doc.collab.utils.Encodings

public class Encodings extends Object
We 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 Details

    • writeStructs

      public static void writeStructs(UpdateEncoder encoder, 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, Map<Integer,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 Map<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, 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, 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, Object transactionOrigin, 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, 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, Map<Integer,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 Map<Integer,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 Map<Integer,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, Map<Integer,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(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(Map<Integer,Integer> doc)
      Encode State as Uint8Array.
      Parameters:
      doc - The state vector map
      Returns:
      The encoded state vector as a byte array.