-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathencodeAndAddWellKnownMetadata.ts
More file actions
44 lines (38 loc) · 1.25 KB
/
encodeAndAddWellKnownMetadata.ts
File metadata and controls
44 lines (38 loc) · 1.25 KB
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
import {
encodeAndAddWellKnownMetadata,
WellKnownMimeType,
} from "@rsocket/composite-metadata";
import { readUInt24BE } from "@rsocket/core";
describe("encodeWellKnownMetadataHeader", () => {
it("encodes the header as per spec when WellKnownMimeType given", () => {
const metadata = encodeAndAddWellKnownMetadata(
Buffer.from([]),
WellKnownMimeType.MESSAGE_RSOCKET_MIMETYPE,
Buffer.from("test")
);
// 122 | 128
const maskedId = metadata.readUInt8(0);
const length = readUInt24BE(metadata, 1);
const value = metadata.slice(4, metadata.length);
expect(maskedId).toBe(250);
expect(length).toBe(4);
expect(value.length).toBe(4);
expect(value.toString("utf-8")).toBe("test");
});
it("encodes the header as per spec when identifier given", () => {
const metadata = encodeAndAddWellKnownMetadata(
Buffer.from([]),
// MESSAGE_RSOCKET_MIMETYPE
122,
Buffer.from("test")
);
// 122 | 128
const maskedId = metadata.readUInt8(0);
const length = readUInt24BE(metadata, 1);
const value = metadata.slice(4, metadata.length);
expect(maskedId).toBe(250);
expect(length).toBe(4);
expect(value.length).toBe(4);
expect(value.toString("utf-8")).toBe("test");
});
});