swc/bundler/tests/.cache/deno/f451b711a14917283d138f2916e827d24744f455.ts
강동윤 bbaf619f63
fix(bundler): Fix bugs (#1437)
swc_bundler:
 - [x] Fix wrapped esms. (denoland/deno#9307)
 - [x] Make test secure.
2021-03-02 17:33:03 +09:00

41 lines
1005 B
TypeScript

// Loaded from https://deno.land/x/mongo@v0.20.0/src/protocol/header.ts
export enum OpCode {
REPLAY = 1,
UPDATE = 2001,
INSERT = 2002,
RESERVED = 2003,
QUERY = 2004,
GET_MORE = 2005,
DELETE = 2006,
KILL_CURSORS = 2007,
MSG = 2013,
}
export interface MessageHeader {
messageLength: number;
requestId: number;
responseTo: number;
opCode: OpCode;
}
export function serializeHeader(header: MessageHeader): Uint8Array {
const view = new DataView(new ArrayBuffer(16));
view.setInt32(0, header.messageLength, true);
view.setInt32(4, header.requestId, true);
view.setInt32(8, header.responseTo, true);
view.setInt32(12, header.opCode, true);
return new Uint8Array(view.buffer);
}
export function parseHeader(buffer: Uint8Array): MessageHeader {
const view = new DataView(buffer.buffer);
return {
messageLength: view.getUint32(0, true),
requestId: view.getUint32(4, true),
responseTo: view.getUint32(8, true),
opCode: view.getUint32(12, true),
};
}