Add session, client and server with the promise result API
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { cmds, cmdsById } from './commands.ts';
|
||||
import { consts, constsById } from './constants.ts';
|
||||
import { encodings } from './encodings.ts';
|
||||
import { errors, errorsById } from './errors.ts';
|
||||
import { tlvs, tlvsById } from './tlvs.ts';
|
||||
import { types } from './types.ts';
|
||||
|
||||
export const defs = {
|
||||
cmds,
|
||||
cmdsById,
|
||||
consts,
|
||||
constsById,
|
||||
encodings,
|
||||
errors,
|
||||
errorsById,
|
||||
tlvs,
|
||||
tlvsById,
|
||||
types,
|
||||
};
|
||||
@@ -24,6 +24,15 @@ export type WireType<T extends ParamValue = ParamValue> = {
|
||||
write: (value: ParamValue, buffer: Buffer, offset: number) => VoidResult;
|
||||
};
|
||||
|
||||
/** Renders a parameter as text without ever falling back to "[object Object]". */
|
||||
export function paramText(value: ParamValue | undefined): string {
|
||||
if (typeof value === 'string') return value;
|
||||
if (typeof value === 'number') return value.toString();
|
||||
if (Buffer.isBuffer(value)) return value.toString('ascii');
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
function outOfRange(buffer: Buffer, offset: number, needed: number): Error | undefined {
|
||||
if (offset < 0 || needed < 0 || offset + needed > buffer.length) {
|
||||
return new Error(
|
||||
|
||||
Reference in New Issue
Block a user