* Add serializeError import to multiSocket.ts and implement preencode and encode functions using JSON serialization for error messages.

This commit is contained in:
Derrick Hammer 2023-04-16 14:29:07 -04:00
parent 3a41474b26
commit e19e4c1744
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 9 additions and 1 deletions

View File

@ -1,7 +1,7 @@
import Proxy, { ProxyOptions } from "../proxy.js"; import Proxy, { ProxyOptions } from "../proxy.js";
import TcpSocket from "./multiSocket/tcpSocket.js"; import TcpSocket from "./multiSocket/tcpSocket.js";
import { json, raw, uint } from "compact-encoding"; import { json, raw, uint } from "compact-encoding";
import { deserializeError } from "serialize-error"; import { deserializeError, serializeError } from "serialize-error";
import b4a from "b4a"; import b4a from "b4a";
import type { TcpSocketConnectOpts } from "net"; import type { TcpSocketConnectOpts } from "net";
import { DataSocketOptions, PeerOptions } from "../peer.js"; import { DataSocketOptions, PeerOptions } from "../peer.js";
@ -62,6 +62,14 @@ const writeSocketEncoding = {
}; };
const errorSocketEncoding = { const errorSocketEncoding = {
preencode(state: any, m: ErrorSocketRequest) {
socketEncoding.preencode(state, m);
json.preencode(state, serializeError(m.err));
},
encode(state: any, m: ErrorSocketRequest) {
socketEncoding.encode(state, m);
json.encode(state, serializeError(m.err));
},
decode(state: any, m: any): ErrorSocketRequest { decode(state: any, m: any): ErrorSocketRequest {
const socket = socketEncoding.decode(state, m); const socket = socketEncoding.decode(state, m);
return { return {