Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame^] | 1 | /* eslint-disable @typescript-eslint/no-namespace */ |
| 2 | import { Builder } from './flexbuffers/builder' |
| 3 | import { toReference as toReferenceFunction } from './flexbuffers/reference'; |
| 4 | |
| 5 | export function builder(): Builder { |
| 6 | return new Builder(); |
| 7 | } |
| 8 | |
| 9 | export function toObject(buffer: Uint8Array): unknown { |
| 10 | return toReferenceFunction(buffer).toObject(); |
| 11 | } |
| 12 | |
| 13 | export function encode(object: unknown, size = 2048, deduplicateStrings = true, deduplicateKeys = true, deduplicateKeyVectors = true): Uint8Array { |
| 14 | const builder = new Builder(size > 0 ? size : 2048, deduplicateStrings, deduplicateKeys, deduplicateKeyVectors); |
| 15 | builder.add(object); |
| 16 | return builder.finish(); |
| 17 | } |
| 18 | |
| 19 | const builderFunction = builder |
| 20 | const toObjectFunction = toObject |
| 21 | const encodeFunction = encode |
| 22 | |
| 23 | export namespace flexbuffers { |
| 24 | export const builder = builderFunction; |
| 25 | export const toObject = toObjectFunction; |
| 26 | export const encode = encodeFunction; |
| 27 | export const toReference = toReferenceFunction; |
| 28 | } |
| 29 | |
| 30 | export default flexbuffers; |