in src/BinaryObject.ts [334:370]
async _write(communicator, buffer) {
if (this._buffer && !this._modified) {
buffer.writeBuffer(this._buffer.buffer, this._startPos, this._startPos + this._length);
}
else {
await this._typeBuilder.finalize(communicator);
this._startPos = buffer.position;
buffer.position = this._startPos + HEADER_LENGTH;
this._hasSchema = (this._fields.size > 0);
if (this._hasSchema) {
let field;
// write fields
for (field of this._fields.values()) {
await field._writeValue(communicator, buffer, this._typeBuilder.getField(field.id).typeCode);
}
this._schemaOffset = buffer.position - this._startPos;
this._offsetType = field.getOffsetType(this._startPos);
// write schema
for (let field of this._fields.values()) {
field._writeOffset(buffer, this._startPos, this._offsetType);
}
}
else {
this._schemaOffset = 0;
}
this._length = buffer.position - this._startPos;
this._buffer = buffer;
// write header
this._writeHeader();
this._buffer.position = this._startPos + this._length;
this._modified = false;
}
if (Logger.debug) {
Logger.logDebug('BinaryObject._write [' + [...this._buffer.getSlice(this._startPos, this._startPos + this._length)] + ']');
}
}