switch from deprecated types

This commit is contained in:
Moon Man 2024-01-28 18:40:22 -05:00
parent f2baff2816
commit 996fea2eeb
3 changed files with 37 additions and 32 deletions

40
dist/bert.d.ts vendored
View File

@ -1,26 +1,26 @@
/// <reference types="node" />
export declare const Types: {
BERT_START: number;
SMALL_ATOM: number;
ATOM: number;
BINARY: number;
SMALL_INTEGER: number;
INTEGER: number;
SMALL_BIG: number;
LARGE_BIG: number;
FLOAT: number;
STRING: number;
LIST: number;
SMALL_TUPLE: number;
LARGE_TUPLE: number;
MAP: number;
NIL: number;
NEW_FLOAT: number;
ZERO: number;
readonly BERT_START: 131;
readonly SMALL_ATOM: 119;
readonly ATOM: 118;
readonly BINARY: 109;
readonly SMALL_INTEGER: 97;
readonly INTEGER: 98;
readonly SMALL_BIG: 110;
readonly LARGE_BIG: 111;
readonly FLOAT: 99;
readonly STRING: 107;
readonly LIST: 108;
readonly SMALL_TUPLE: 104;
readonly LARGE_TUPLE: 105;
readonly MAP: 116;
readonly NIL: 106;
readonly NEW_FLOAT: 70;
readonly ZERO: 0;
};
export declare const Lang: {
ELIXIR: number;
ERLANG: number;
readonly ELIXIR: 0;
readonly ERLANG: 1;
};
export declare class Bert {
#private;
@ -29,7 +29,7 @@ export declare class Bert {
private decodeUndefinedValues;
private convention;
private outputBuffer;
constructor(allBinariesAsString?: boolean, mapKeyAsAtom?: boolean, decodeUndefinedValues?: boolean, convention?: number);
constructor(allBinariesAsString?: boolean, mapKeyAsAtom?: boolean, decodeUndefinedValues?: boolean, convention?: 0 | 1);
toAtom: (str: string) => {
type: string;
value: string;

4
dist/bert.js vendored
View File

@ -1,7 +1,7 @@
export const Types = {
BERT_START: 131,
SMALL_ATOM: 115,
ATOM: 100,
SMALL_ATOM: 119,
ATOM: 118,
BINARY: 109,
SMALL_INTEGER: 97,
INTEGER: 98,

View File

@ -1,7 +1,7 @@
export const Types = {
BERT_START: 131,
SMALL_ATOM: 115,
ATOM: 100,
SMALL_ATOM: 119,
ATOM: 118,
BINARY: 109,
SMALL_INTEGER: 97,
INTEGER: 98,
@ -16,12 +16,12 @@ export const Types = {
NIL: 106,
NEW_FLOAT: 70,
ZERO: 0,
};
} as const;
export const Lang = {
ELIXIR: 0,
ERLANG: 1,
};
} as const;
export class Bert {
private allBinariesAsString;
@ -34,7 +34,7 @@ export class Bert {
allBinariesAsString = false,
mapKeyAsAtom = true,
decodeUndefinedValues = true,
convention = Lang.ELIXIR,
convention: 0 | 1 = Lang.ELIXIR,
) {
this.allBinariesAsString = allBinariesAsString;
this.mapKeyAsAtom = mapKeyAsAtom;
@ -303,23 +303,28 @@ export class Bert {
let value: any = buffer.toString("utf8", 0, size);
if (value === "true") {
value = true;
} else if (value === "false") {
}
else if (value === "false") {
value = false;
} else if (
}
else if (
this.decodeUndefinedValues &&
this.convention === Lang.ELIXIR &&
value === "nil"
) {
value = null;
} else if (
}
else if (
this.decodeUndefinedValues &&
this.convention === Lang.ERLANG &&
value === "undefined"
) {
value = null;
} else {
}
else {
value = this.toAtom(value);
}
return {
value,
rest: buffer.subarray(size),
@ -391,7 +396,7 @@ export class Bert {
};
decode_string = (buffer: Buffer) => {
const sizeLen = this.convention === Lang.ELIXIR ? 4 : 2;
const sizeLen = this.convention === Lang.ELIXIR ? 4 : 2;
const size = this.bytesToInt(buffer, sizeLen, true);
buffer = buffer.subarray(sizeLen);