1 | ;
|
2 | // *****************************************************************************
|
3 | // Copyright (C) 2022 STMicroelectronics and others.
|
4 | //
|
5 | // This program and the accompanying materials are made available under the
|
6 | // terms of the Eclipse Public License v. 2.0 which is available at
|
7 | // http://www.eclipse.org/legal/epl-2.0.
|
8 | //
|
9 | // This Source Code may also be made available under the following Secondary
|
10 | // Licenses when the conditions for such availability set forth in the Eclipse
|
11 | // Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
12 | // with the GNU Classpath Exception which is available at
|
13 | // https://www.gnu.org/software/classpath/license.html.
|
14 | //
|
15 | // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
16 | // *****************************************************************************
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.MsgPackExtensionManager = void 0;
|
19 | const msgpackr_1 = require("msgpackr");
|
20 | /**
|
21 | * Handles the global registration of custom MsgPackR extensions
|
22 | * required for the default RPC communication. MsgPackR extensions
|
23 | * are installed globally on both ends of the communication channel.
|
24 | * (frontend-backend, pluginExt-pluginMain).
|
25 | * Is implemented as singleton as it is also used in plugin child processes which have no access to inversify.
|
26 | */
|
27 | class MsgPackExtensionManager {
|
28 | constructor() {
|
29 | this.extensions = new Map();
|
30 | }
|
31 | static getInstance() {
|
32 | return this.INSTANCE;
|
33 | }
|
34 | registerExtensions(...extensions) {
|
35 | extensions.forEach(extension => {
|
36 | if (extension.tag < 1 || extension.tag > 100) {
|
37 | // MsgPackR reserves the tag range 1-100 for custom extensions.
|
38 | throw new Error(`MsgPack extension tag should be a number from 1-100 but was '${extension.tag}'`);
|
39 | }
|
40 | if (this.extensions.has(extension.tag)) {
|
41 | throw new Error(`Another MsgPack extension with the tag '${extension.tag}' is already registered`);
|
42 | }
|
43 | this.extensions.set(extension.tag, extension);
|
44 | (0, msgpackr_1.addExtension)({
|
45 | Class: extension.class,
|
46 | type: extension.tag,
|
47 | write: extension.serialize,
|
48 | read: extension.deserialize
|
49 | });
|
50 | });
|
51 | }
|
52 | getExtension(tag) {
|
53 | return this.extensions.get(tag);
|
54 | }
|
55 | }
|
56 | exports.MsgPackExtensionManager = MsgPackExtensionManager;
|
57 | MsgPackExtensionManager.INSTANCE = new MsgPackExtensionManager();
|
58 | //# sourceMappingURL=msg-pack-extension-manager.js.map |
\ | No newline at end of file |