_writeHeader()

in src/BinaryObject.ts [375:405]


    _writeHeader() {
        this._buffer.position = this._startPos;
        // type code
        this._buffer.writeByte(BinaryUtils.TYPE_CODE.COMPLEX_OBJECT);
        // version
        this._buffer.writeByte(VERSION);
        // flags
        let flags = FLAG_USER_TYPE;
        if (this._hasSchema) {
            flags = flags | FLAG_HAS_SCHEMA | FLAG_COMPACT_FOOTER;
        }
        if (this._offsetType === BinaryUtils.TYPE_CODE.BYTE) {
            flags = flags | FLAG_OFFSET_ONE_BYTE;
        }
        else if (this._offsetType === BinaryUtils.TYPE_CODE.SHORT) {
            flags = flags | FLAG_OFFSET_TWO_BYTES;
        }
        this._buffer.writeShort(flags);
        // type id
        this._buffer.writeInteger(this._typeBuilder.getTypeId());
        // hash code
        this._hashCode = BinaryUtils.contentHashCode(
            this._buffer, this._startPos + HEADER_LENGTH, this._schemaOffset - 1);
        this._buffer.writeInteger(this._hashCode);
        // length
        this._buffer.writeInteger(this._length);
        // schema id
        this._buffer.writeInteger(this._hasSchema ? this._typeBuilder.getSchemaId() : 0);
        // schema offset
        this._buffer.writeInteger(this._schemaOffset);
    }