more logging

This commit is contained in:
Moon Man 2024-02-02 14:34:02 -05:00
parent 6fb0cfe889
commit db737af36f
3 changed files with 18 additions and 11 deletions

1
dist/main.d.ts vendored
View File

@ -7,6 +7,7 @@ type ServerHandlerCallback = (reply: "reply" | "noreply", ...extraArgs: any[]) =
type ServerHandler = (term: any, from: any, state: any, callback: ServerHandlerCallback) => void; type ServerHandler = (term: any, from: any, state: any, callback: ServerHandlerCallback) => void;
export declare class Port extends Duplex { export declare class Port extends Duplex {
readonly bert: Bert; readonly bert: Bert;
private lenBuffer;
constructor(allBinariesAsString?: boolean, mapKeyAsAtom?: boolean, decodeUndefinedValues?: boolean); constructor(allBinariesAsString?: boolean, mapKeyAsAtom?: boolean, decodeUndefinedValues?: boolean);
_read(): any; _read(): any;
_write(obj: any, encodingOrCallback?: BufferEncoding | WriteCallback, callback?: WriteCallback | undefined): boolean; _write(obj: any, encodingOrCallback?: BufferEncoding | WriteCallback, callback?: WriteCallback | undefined): boolean;

13
dist/main.js vendored
View File

@ -3,6 +3,7 @@ import { Duplex } from "node:stream";
const log = (msg) => process.stderr.write(`${msg}\r\n`); const log = (msg) => process.stderr.write(`${msg}\r\n`);
export class Port extends Duplex { export class Port extends Duplex {
bert; bert;
lenBuffer = Buffer.alloc(4);
constructor(allBinariesAsString, mapKeyAsAtom, decodeUndefinedValues) { constructor(allBinariesAsString, mapKeyAsAtom, decodeUndefinedValues) {
super({ objectMode: true }); super({ objectMode: true });
this.bert = new Bert(allBinariesAsString, mapKeyAsAtom, decodeUndefinedValues); this.bert = new Bert(allBinariesAsString, mapKeyAsAtom, decodeUndefinedValues);
@ -26,16 +27,18 @@ export class Port extends Duplex {
return null; return null;
} }
} }
else else {
this.push(null);
return null; return null;
}
} }
_write(obj, encodingOrCallback, callback) { _write(obj, encodingOrCallback, callback) {
const actualCallback = callback || typeof encodingOrCallback === "function" ? encodingOrCallback : undefined; const actualCallback = callback || typeof encodingOrCallback === "function" ? encodingOrCallback : undefined;
log(`Port was written to.`);
try { try {
const term = this.bert.encode(obj, true); const term = this.bert.encode(obj, false);
const len = Buffer.alloc(4); this.lenBuffer.writeUInt32BE(term.length);
len.writeUInt32BE(term.length, 0); process.stdout.write(this.lenBuffer);
process.stdout.write(len);
process.stdout.write(term, actualCallback); process.stdout.write(term, actualCallback);
return true; return true;
} }

View File

@ -10,6 +10,7 @@ const log = (msg: string) => process.stderr.write(`${msg}\r\n`);
export class Port extends Duplex { export class Port extends Duplex {
public readonly bert: Bert; public readonly bert: Bert;
private lenBuffer = Buffer.alloc(4);
constructor(allBinariesAsString?: boolean, mapKeyAsAtom?: boolean, decodeUndefinedValues?: boolean) { constructor(allBinariesAsString?: boolean, mapKeyAsAtom?: boolean, decodeUndefinedValues?: boolean) {
super({ objectMode: true }); super({ objectMode: true });
@ -36,18 +37,20 @@ export class Port extends Duplex {
return null; return null;
} }
} }
else return null; else {
this.push(null);
return null;
}
} }
_write(obj: any, encodingOrCallback?: BufferEncoding | WriteCallback, callback?: WriteCallback | undefined) { _write(obj: any, encodingOrCallback?: BufferEncoding | WriteCallback, callback?: WriteCallback | undefined) {
const actualCallback: any = callback || typeof encodingOrCallback === "function" ? encodingOrCallback : undefined; const actualCallback: any = callback || typeof encodingOrCallback === "function" ? encodingOrCallback : undefined;
log(`Port was written to.`);
try { try {
const term = this.bert.encode(obj, true); const term = this.bert.encode(obj, false);
const len = Buffer.alloc(4); this.lenBuffer.writeUInt32BE(term.length);
len.writeUInt32BE(term.length, 0); process.stdout.write(this.lenBuffer);
process.stdout.write(len);
process.stdout.write(term, actualCallback); process.stdout.write(term, actualCallback);
return true; return true;
} }