fix: add legacy constants for decoding

This commit is contained in:
Adhiraj Singh
2022-04-24 16:49:13 +05:30
parent a7e9dcf512
commit 3c278b35f0
7 changed files with 239 additions and 385 deletions

View File

@@ -1,9 +1,14 @@
import { TAGS, TOKEN_MAP } from './constants'
import * as constants from './constants'
import { jidDecode } from './jid-utils'
import type { BinaryNode } from './types'
import type { BinaryNode, BinaryNodeCodingOptions } from './types'
export const encodeBinaryNode = ({ tag, attrs, content }: BinaryNode, buffer: number[] = [0]) => {
export const encodeBinaryNode = (
{ tag, attrs, content }: BinaryNode,
opts: Pick<BinaryNodeCodingOptions, 'TAGS' | 'TOKEN_MAP'> = constants,
buffer: number[] = []
) => {
const { TAGS, TOKEN_MAP } = opts
const pushByte = (value: number) => buffer.push(value & 0xff)
@@ -216,7 +221,7 @@ export const encodeBinaryNode = ({ tag, attrs, content }: BinaryNode, buffer: nu
writeListStart(content.length)
for(const item of content) {
if(item) {
encodeBinaryNode(item, buffer)
encodeBinaryNode(item, opts, buffer)
}
}
} else if(typeof content === 'undefined' || content === null) {