Skip to content

Commit

Permalink
src/jumbf/UUIDBox.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
UlrichEckhardt committed Jul 30, 2024
1 parent 483e299 commit adf62dc
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions src/jumbf/UUIDBox.ts
Original file line number Diff line number Diff line change
@@ -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<UUIDBox> {
readonly length = schemata.length;
readonly type = schemata.type;
class UUIDBoxSchema extends BoxSchema<UUIDBox> {
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);
Expand All @@ -26,20 +23,13 @@ class UUIDBoxSchema extends bin.Schema<UUIDBox> {
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));
}
}

Expand Down

0 comments on commit adf62dc

Please sign in to comment.