Distributed Concurrent Editor

protocol.ts at [ffc3afbe0e]
Login

File http/browser/src/protocol.ts artifact b1bc245995 part of check-in ffc3afbe0e


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//
//       bebopc version:
//           2.3.1
//
//
//       bebopc source:
//           https://github.com/RainwayApp/bebop
//
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
import { BebopView, BebopRuntimeError } from "bebop";

export interface IWordId {
  clientId: bigint;
  counter: bigint;
}

export const WordId = {
  encode(message: IWordId): Uint8Array {
    const view = BebopView.getInstance();
    view.startWriting();
    this.encodeInto(message, view);
    return view.toArray();
  },

  encodeInto(message: IWordId, view: BebopView): number {
    const before = view.length;
      view.writeUint64(message.clientId);
      view.writeUint64(message.counter);
    const after = view.length;
    return after - before;
  },

  decode(buffer: Uint8Array): IWordId {
    const view = BebopView.getInstance();
    view.startReading(buffer);
    return this.readFrom(view);
  },

  readFrom(view: BebopView): IWordId {
    let field0: bigint;
    field0 = view.readUint64();
    let field1: bigint;
    field1 = view.readUint64();
    let message: IWordId = {
      clientId: field0,
      counter: field1,
    };
    return message;
  },
};

export interface IVersion {
  counter: bigint;
  clientId: bigint;
}

export const Version = {
  encode(message: IVersion): Uint8Array {
    const view = BebopView.getInstance();
    view.startWriting();
    this.encodeInto(message, view);
    return view.toArray();
  },

  encodeInto(message: IVersion, view: BebopView): number {
    const before = view.length;
      view.writeUint64(message.counter);
      view.writeUint64(message.clientId);
    const after = view.length;
    return after - before;
  },

  decode(buffer: Uint8Array): IVersion {
    const view = BebopView.getInstance();
    view.startReading(buffer);
    return this.readFrom(view);
  },

  readFrom(view: BebopView): IVersion {
    let field0: bigint;
    field0 = view.readUint64();
    let field1: bigint;
    field1 = view.readUint64();
    let message: IVersion = {
      counter: field0,
      clientId: field1,
    };
    return message;
  },
};

export interface IWord {
  wordId: IWordId;
  version: IVersion;
  letters: string;
  links: ILinks;
}

export const Word = {
  encode(message: IWord): Uint8Array {
    const view = BebopView.getInstance();
    view.startWriting();
    this.encodeInto(message, view);
    return view.toArray();
  },

  encodeInto(message: IWord, view: BebopView): number {
    const before = view.length;
      WordId.encodeInto(message.wordId, view)
      Version.encodeInto(message.version, view)
      view.writeString(message.letters);
      Links.encodeInto(message.links, view)
    const after = view.length;
    return after - before;
  },

  decode(buffer: Uint8Array): IWord {
    const view = BebopView.getInstance();
    view.startReading(buffer);
    return this.readFrom(view);
  },

  readFrom(view: BebopView): IWord {
    let field0: IWordId;
    field0 = WordId.readFrom(view);
    let field1: IVersion;
    field1 = Version.readFrom(view);
    let field2: string;
    field2 = view.readString();
    let field3: ILinks;
    field3 = Links.readFrom(view);
    let message: IWord = {
      wordId: field0,
      version: field1,
      letters: field2,
      links: field3,
    };
    return message;
  },
};

export interface ILinks {
  previous?: IWordId;
  next?: IWordId;
}

export const Links = {
  encode(message: ILinks): Uint8Array {
    const view = BebopView.getInstance();
    view.startWriting();
    this.encodeInto(message, view);
    return view.toArray();
  },

  encodeInto(message: ILinks, view: BebopView): number {
    const before = view.length;
      const pos = view.reserveMessageLength();
      const start = view.length;
      if (message.previous != null) {
        view.writeByte(1);
        WordId.encodeInto(message.previous, view)
      }
      if (message.next != null) {
        view.writeByte(2);
        WordId.encodeInto(message.next, view)
      }
      view.writeByte(0);
      const end = view.length;
      view.fillMessageLength(pos, end - start);
    const after = view.length;
    return after - before;
  },

  decode(buffer: Uint8Array): ILinks {
    const view = BebopView.getInstance();
    view.startReading(buffer);
    return this.readFrom(view);
  },

  readFrom(view: BebopView): ILinks {
    let message: ILinks = {};
    const length = view.readMessageLength();
    const end = view.index + length;
    while (true) {
      switch (view.readByte()) {
        case 0:
          return message;

        case 1:
          message.previous = WordId.readFrom(view);
          break;

        case 2:
          message.next = WordId.readFrom(view);
          break;

        default:
          view.index = end;
          return message;
      }
    }
  },
};

export interface IMessage {
  updates?: Array<IWord>;
  undo?: boolean;
  redo?: boolean;
}

export const Message = {
  encode(message: IMessage): Uint8Array {
    const view = BebopView.getInstance();
    view.startWriting();
    this.encodeInto(message, view);
    return view.toArray();
  },

  encodeInto(message: IMessage, view: BebopView): number {
    const before = view.length;
      const pos = view.reserveMessageLength();
      const start = view.length;
      if (message.updates != null) {
        view.writeByte(1);
        {
        const length0 = message.updates.length;
        view.writeUint32(length0);
        for (let i0 = 0; i0 < length0; i0++) {
          Word.encodeInto(message.updates[i0], view)
        }
      }
      }
      if (message.undo != null) {
        view.writeByte(2);
        view.writeByte(Number(message.undo));
      }
      if (message.redo != null) {
        view.writeByte(3);
        view.writeByte(Number(message.redo));
      }
      view.writeByte(0);
      const end = view.length;
      view.fillMessageLength(pos, end - start);
    const after = view.length;
    return after - before;
  },

  decode(buffer: Uint8Array): IMessage {
    const view = BebopView.getInstance();
    view.startReading(buffer);
    return this.readFrom(view);
  },

  readFrom(view: BebopView): IMessage {
    let message: IMessage = {};
    const length = view.readMessageLength();
    const end = view.index + length;
    while (true) {
      switch (view.readByte()) {
        case 0:
          return message;

        case 1:
          {
        let length0 = view.readUint32();
        message.updates = new Array<IWord>(length0);
        for (let i0 = 0; i0 < length0; i0++) {
          let x0: IWord;
          x0 = Word.readFrom(view);
          message.updates[i0] = x0;
        }
      }
          break;

        case 2:
          message.undo = !!view.readByte();
          break;

        case 3:
          message.redo = !!view.readByte();
          break;

        default:
          view.index = end;
          return message;
      }
    }
  },
};