summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Harrtell <bjornharrtell@users.noreply.github.com>2022-02-11 18:40:09 +0100
committerGitHub <noreply@github.com>2022-02-11 09:40:09 -0800
commit48befb6bef6a81f68356f9da8c7a5934d34a78d0 (patch)
treeb818f189dddce7803a44293854a2bfda1abc02a0
parentb3006913369e0a7550795e477011ac5bebb93497 (diff)
downloadflatbuffers-48befb6bef6a81f68356f9da8c7a5934d34a78d0.tar.gz
flatbuffers-48befb6bef6a81f68356f9da8c7a5934d34a78d0.tar.bz2
flatbuffers-48befb6bef6a81f68356f9da8c7a5934d34a78d0.zip
[TS] Refactor away circular ref (#7099)
-rw-r--r--ts/flexbuffers/reference-util.ts8
-rw-r--r--ts/flexbuffers/reference.ts11
2 files changed, 9 insertions, 10 deletions
diff --git a/ts/flexbuffers/reference-util.ts b/ts/flexbuffers/reference-util.ts
index 410d2af9..c55a941a 100644
--- a/ts/flexbuffers/reference-util.ts
+++ b/ts/flexbuffers/reference-util.ts
@@ -1,7 +1,6 @@
import { BitWidth } from './bit-width.js'
import { toByteWidth, fromByteWidth } from './bit-width-util.js'
import { toUTF8Array, fromUTF8Array } from './flexbuffers-util.js'
-import { Reference } from './reference.js'
export function validateOffset(dataView: DataView, offset: number, width: number): void {
if (dataView.byteLength <= offset + width || (offset & (toByteWidth(width) - 1)) !== 0) {
@@ -95,13 +94,6 @@ export function diffKeys(input: Uint8Array, index: number, dataView: DataView, o
return dataView.getUint8(keyIndirectOffset + input.length) === 0 ? 0 : -1;
}
-export function valueForIndexWithKey(index: number, key: string, dataView: DataView, offset: number, parentWidth: number, byteWidth: number, length: number, path: string): Reference {
- const _indirect = indirect(dataView, offset, parentWidth);
- const elementOffset = _indirect + index * byteWidth;
- const packedType = dataView.getUint8(_indirect + length * byteWidth + index);
- return new Reference(dataView, elementOffset, fromByteWidth(byteWidth), packedType, `${path}/${key}`)
-}
-
export function keyForIndex(index: number, dataView: DataView, offset: number, parentWidth: number, byteWidth: number): string {
const keysVectorOffset = indirect(dataView, offset, parentWidth) - byteWidth * 3;
const bitWidth = fromByteWidth(byteWidth);
diff --git a/ts/flexbuffers/reference.ts b/ts/flexbuffers/reference.ts
index 53f3ff06..0eff6f46 100644
--- a/ts/flexbuffers/reference.ts
+++ b/ts/flexbuffers/reference.ts
@@ -1,13 +1,13 @@
import { fromByteWidth } from './bit-width-util.js'
import { ValueType } from './value-type.js'
import { isNumber, isIndirectNumber, isAVector, fixedTypedVectorElementSize, isFixedTypedVector, isTypedVector, typedVectorElementType, packedType, fixedTypedVectorElementType } from './value-type-util.js'
-import { indirect, keyForIndex, keyIndex, readFloat, readInt, readUInt, valueForIndexWithKey } from './reference-util.js'
+import { indirect, keyForIndex, keyIndex, readFloat, readInt, readUInt } from './reference-util.js'
import { fromUTF8Array } from './flexbuffers-util.js';
import { BitWidth } from './bit-width.js';
export function toReference(buffer: ArrayBuffer): Reference {
const len = buffer.byteLength;
-
+
if (len < 3) {
throw "Buffer needs to be bigger than 3";
}
@@ -21,6 +21,13 @@ export function toReference(buffer: ArrayBuffer): Reference {
return new Reference(dataView, offset, parentWidth, packedType, "/")
}
+function valueForIndexWithKey(index: number, key: string, dataView: DataView, offset: number, parentWidth: number, byteWidth: number, length: number, path: string): Reference {
+ const _indirect = indirect(dataView, offset, parentWidth);
+ const elementOffset = _indirect + index * byteWidth;
+ const packedType = dataView.getUint8(_indirect + length * byteWidth + index);
+ return new Reference(dataView, elementOffset, fromByteWidth(byteWidth), packedType, `${path}/${key}`)
+}
+
export class Reference {
private readonly byteWidth: number
private readonly valueType: ValueType