rpcProtocol.ts ×15

Frontier kind: Joint frontier

unlabeled · c_b5dc455d9be3

1 test · 8534 LOC · 37 files · introduces 1 test · 94 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
16 ranges94 lines · 2 files
Tests
1 test

Contains — complete concept membership

All code (extent)
1392 ranges8534 lines · 37 files · Browse complete extent
All tests (intent)
1 testBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

1 test introduced at this concept.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

2 files ranked by introduced lines: 94 introduced LOC across 16 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/services/extensions/common/rpcProtocol.ts 92 introduced LOC · 15 ranges

Open complete file

41
42 export function stringifyJsonWithBufferRefs<T>(obj: T, replacer: JSONStringifyReplacer | null = null, useSafeStringify = false): StringifiedJsonWithBufferRefs {
43 > const foundBuffers: VSBuffer[] = []; rpcProtocol.ts
44 > const serialized = (useSafeStringify ? safeStringify : JSON.stringify)(obj, (key, value) => {
45 > if (typeof value === 'undefined') {
46 return undefinedRef; // JSON.stringify normally converts 'undefined' to 'null'
47 > } else if (typeof value === 'object') { rpcProtocol.ts
48 > if (value instanceof VSBuffer) {
49 > const bufferIndex = foundBuffers.push(value) - 1;
50 > return { [refSymbolName]: bufferIndex };
51 > }
52 > if (replacer) {
53 return replacer(key, value);
54 }
56 > return value;
57 > });
58 > return {
59 > jsonString: serialized,
60 > referencedBuffers: foundBuffers
61 > };
62 > }
63
64 export function parseJsonAndRestoreBufferRefs(jsonString: string, buffers: readonly VSBuffer[], uriTransformer: IURITransformer | null): any {
65 > return JSON.parse(jsonString, (_key, value) => { rpcProtocol.ts
66 > if (value) {
67 > const ref = value[refSymbolName];
68 > if (typeof ref === 'number') {
69 > return buffers[ref];
70 > }
71 >
72 > if (uriTransformer && (<MarshalledObject>value).$mid === MarshalledId.Uri) {
73 return uriTransformer.transformIncoming(value);
74 }
76 > return value;
77 > });
78 > }
79
80
331 }
332 case MessageType.ReplyOKJSONWithBuffers: {
333 > const value = MessageIO.deserializeReplyOKJSONWithBuffers(buff, this._uriTransformer); rpcProtocol.ts
334 > this._receiveReply(msgLength, req, value);
335 > break;
336 > }
337 case MessageType.ReplyOKVSBuffer: {
338 const value = MessageIO.deserializeReplyOKVSBuffer(buff);
596
597 public writeBuffer(buff: VSBuffer): void {
598 > this._buff.writeUInt32BE(buff.byteLength, this._offset); this._offset += 4; rpcProtocol.ts
599 > this._buff.set(buff, this._offset); this._offset += buff.byteLength;
600 > }
601
602 public static sizeVSBuffer(buff: VSBuffer): number {
629 break;
630 case ArgType.SerializedObjectWithBuffers:
631 > size += this.sizeUInt32; // buffer count rpcProtocol.ts
632 > size += this.sizeLongString(el.value);
633 > for (let i = 0; i < el.buffers.length; ++i) {
634 > size += this.sizeVSBuffer(el.buffers[i]);
635 > }
636 > break;
637 case ArgType.Undefined:
638 // empty...
657 break;
658 case ArgType.SerializedObjectWithBuffers:
659 > this.writeUInt8(ArgType.SerializedObjectWithBuffers); rpcProtocol.ts
660 > this.writeUInt32(el.buffers.length);
661 > this.writeLongString(el.value);
662 > for (let i = 0; i < el.buffers.length; ++i) {
663 > this.writeBuffer(el.buffers[i]);
664 > }
665 > break;
666 case ArgType.Undefined:
667 this.writeUInt8(ArgType.Undefined);
684 break;
685 case ArgType.SerializedObjectWithBuffers: {
686 > const bufferCount = this.readUInt32(); rpcProtocol.ts
687 > const jsonString = this.readLongString();
688 > const buffers: VSBuffer[] = [];
689 > for (let i = 0; i < bufferCount; ++i) {
690 > buffers.push(this.readVSBuffer());
691 > }
692 > arr[i] = new SerializableObjectWithBuffers(parseJsonAndRestoreBufferRefs(jsonString, buffers, null));
693 > break;
694 > }
695 case ArgType.Undefined:
696 arr[i] = undefined;
720 }
721 if (arr[i] instanceof SerializableObjectWithBuffers) {
722 > return true; rpcProtocol.ts
723 > }
724 if (typeof arr[i] === 'undefined') {
725 return true;
739 massagedArgs[i] = { type: ArgType.Undefined };
740 } else if (arg instanceof SerializableObjectWithBuffers) {
741 > const { jsonString, referencedBuffers } = stringifyJsonWithBufferRefs(arg.value, replacer); rpcProtocol.ts
742 > massagedArgs[i] = { type: ArgType.SerializedObjectWithBuffers, value: VSBuffer.fromString(jsonString), buffers: referencedBuffers };
743 } else {
744 massagedArgs[i] = { type: ArgType.String, value: VSBuffer.fromString(stringify(arg, replacer)) };
841 return this._serializeReplyOKVSBuffer(req, res);
842 } else if (res instanceof SerializableObjectWithBuffers) {
843 > const { jsonString, referencedBuffers } = stringifyJsonWithBufferRefs(res.value, replacer, true); rpcProtocol.ts
844 > return this._serializeReplyOKJSONWithBuffers(req, jsonString, referencedBuffers);
845 } else {
846 return this._serializeReplyOKJSON(req, safeStringify(res, replacer));
877
878 private static _serializeReplyOKJSONWithBuffers(req: number, res: string, buffers: readonly VSBuffer[]): VSBuffer {
879 > const resBuff = VSBuffer.fromString(res); rpcProtocol.ts
880 >
881 > let len = 0;
882 > len += MessageBuffer.sizeUInt32; // buffer count
883 > len += MessageBuffer.sizeLongString(resBuff);
884 > for (const buffer of buffers) {
885 > len += MessageBuffer.sizeVSBuffer(buffer);
886 > }
887 >
888 > const result = MessageBuffer.alloc(MessageType.ReplyOKJSONWithBuffers, req, len);
889 > result.writeUInt32(buffers.length);
890 > result.writeLongString(resBuff);
891 > for (const buffer of buffers) {
892 > result.writeBuffer(buffer);
893 > }
894 >
895 > return result.buffer;
896 > }
897
898 public static deserializeReplyOKJSON(buff: MessageBuffer): any {
902
903 public static deserializeReplyOKJSONWithBuffers(buff: MessageBuffer, uriTransformer: IURITransformer | null): SerializableObjectWithBuffers<any> {
904 > const bufferCount = buff.readUInt32(); rpcProtocol.ts
905 > const res = buff.readLongString();
906 >
907 > const buffers: VSBuffer[] = [];
908 > for (let i = 0; i < bufferCount; ++i) {
909 > buffers.push(buff.readVSBuffer());
910 > }
911 >
912 > return new SerializableObjectWithBuffers(parseJsonAndRestoreBufferRefs(res, buffers, uriTransformer));
913 > }
914
915 public static serializeReplyErr(req: number, err: any): VSBuffer {
src/vs/workbench/services/extensions/common/proxyIdentifier.ts 2 introduced LOC · 1 range

Open complete file

81 export class SerializableObjectWithBuffers<T> {
82 constructor(
83 > public readonly value: T proxyIdentifier.ts
84 > ) { }
85 }