mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-01 19:58:15 +00:00
[TS] Refactor away circular ref (#7099)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
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';
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user