xcom2charpool
Version:
Library for reading, manipulating, and managing XCOM 2 character pool binary files, supporting both browser and Node.js environments.
28 lines (27 loc) • 994 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ByteArrayElement = void 0;
const BytePropertyValue_1 = require("./BytePropertyValue");
const BaseCodec_1 = require("../../BaseCodec");
const CodecError_1 = require("../../Errors/CodecError");
/**
* Array element codec for BytePropertyValue entries inside ArrayProperty payloads.
*/
class ByteArrayElement extends BaseCodec_1.BaseCodec {
constructor(type) {
super();
this.type = type;
}
read(reader, ctx) {
const value = reader.string();
reader.padding();
return new BytePropertyValue_1.BytePropertyValue(this.type, value);
}
write(writer, value, ctx) {
if (value.type !== this.type) {
throw new CodecError_1.CodecError(`Byte array element type mismatch: expected ${this.type}, got ${value.type}`, this.fullPath(ctx));
}
writer.string(value.value).padding();
}
}
exports.ByteArrayElement = ByteArrayElement;