From adf62dcf1179e171c449d5fdb11e3b7eab3e2415 Mon Sep 17 00:00:00 2001 From: Ulrich Eckhardt Date: Tue, 30 Jul 2024 12:43:37 +0200 Subject: [PATCH] src/jumbf/UUIDBox.ts --- src/jumbf/UUIDBox.ts | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/jumbf/UUIDBox.ts b/src/jumbf/UUIDBox.ts index 3f50c804..0765fa18 100644 --- a/src/jumbf/UUIDBox.ts +++ b/src/jumbf/UUIDBox.ts @@ -1,16 +1,13 @@ import * as bin from 'typed-binary'; import { BinaryHelper } from '../util'; import { Box } from './Box'; +import { BoxSchema } from './BoxSchema'; import * as schemata from './schemata'; -class UUIDBoxSchema extends bin.Schema { - readonly length = schemata.length; - readonly type = schemata.type; +class UUIDBoxSchema extends BoxSchema { readonly uuid = schemata.uuid; - read(input: bin.ISerialInput): UUIDBox { - const length = this.length.read(input); - const type = this.type.read(input); + readContent(input: bin.ISerialInput, type: string, length: number): UUIDBox { if (type != UUIDBox.typeCode) throw new Error(`UUIDBox: Unexpected type ${type}`); const uuid = this.uuid.read(input); @@ -26,20 +23,13 @@ class UUIDBoxSchema extends bin.Schema { return box; } - write(output: bin.ISerialOutput, value: UUIDBox): void { - this.length.write(output, this.measure(value).size); - this.type.write(output, value.type); + writeContent(output: bin.ISerialOutput, value: UUIDBox): void { this.uuid.write(output, value.uuid); value.content?.forEach(byte => output.writeByte(byte)); } - measure(value: UUIDBox, measurer: bin.IMeasurer = new bin.Measurer()): bin.IMeasurer { - return measurer.add( - 4 + // length - 4 + // type - this.uuid.measure(value.uuid).size + - (value.content ? value.content.length : 0), - ); + measureContent(value: UUIDBox, measurer: bin.IMeasurer): bin.IMeasurer { + return measurer.add(this.uuid.measure(value.uuid).size + (value.content ? value.content.length : 0)); } }