snapshot of https://github.com/ueberdosis/hocuspocus.git @ cf3cfa355b4d3bb61c6b6c80071f71783e32470e (2026-09-15)
Some checks failed
build / lint (22) (push) Failing after 17s
build / test (22) (push) Failing after 8s
build / lint (23) (push) Failing after 2s
build / build (22) (push) Has been skipped
build / build (23) (push) Has been skipped
build / test (23) (push) Failing after 4s
docsearch / docsearch (push) Failing after 1s
Some checks failed
build / lint (22) (push) Failing after 17s
build / test (22) (push) Failing after 8s
build / lint (23) (push) Failing after 2s
build / build (22) (push) Has been skipped
build / build (23) (push) Has been skipped
build / test (23) (push) Failing after 4s
docsearch / docsearch (push) Failing after 1s
This commit is contained in:
63
packages/provider/src/IncomingMessage.ts
Normal file
63
packages/provider/src/IncomingMessage.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import type { Decoder } from "lib0/decoding";
|
||||
import {
|
||||
createDecoder,
|
||||
peekVarString,
|
||||
readVarUint,
|
||||
readVarUint8Array,
|
||||
readVarString,
|
||||
} from "lib0/decoding";
|
||||
import type { Encoder } from "lib0/encoding";
|
||||
import {
|
||||
createEncoder,
|
||||
writeVarUint,
|
||||
writeVarUint8Array,
|
||||
writeVarString,
|
||||
length,
|
||||
} from "lib0/encoding";
|
||||
import type { MessageType } from "./types.ts";
|
||||
|
||||
export class IncomingMessage {
|
||||
data: any;
|
||||
|
||||
encoder: Encoder;
|
||||
|
||||
decoder: Decoder;
|
||||
|
||||
constructor(data: any) {
|
||||
this.data = data;
|
||||
this.encoder = createEncoder();
|
||||
this.decoder = createDecoder(new Uint8Array(this.data));
|
||||
}
|
||||
|
||||
peekVarString(): string {
|
||||
return peekVarString(this.decoder);
|
||||
}
|
||||
|
||||
readVarUint(): MessageType {
|
||||
return readVarUint(this.decoder);
|
||||
}
|
||||
|
||||
readVarString(): string {
|
||||
return readVarString(this.decoder);
|
||||
}
|
||||
|
||||
readVarUint8Array() {
|
||||
return readVarUint8Array(this.decoder);
|
||||
}
|
||||
|
||||
writeVarUint(type: MessageType) {
|
||||
return writeVarUint(this.encoder, type);
|
||||
}
|
||||
|
||||
writeVarString(string: string) {
|
||||
return writeVarString(this.encoder, string);
|
||||
}
|
||||
|
||||
writeVarUint8Array(data: Uint8Array) {
|
||||
return writeVarUint8Array(this.encoder, data);
|
||||
}
|
||||
|
||||
length() {
|
||||
return length(this.encoder);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user