in src/recordlayer.js [165:193]
async send(type, data) {
if (this._sendError !== null) {
throw this._sendError;
}
// Forbid sending data that doesn't fit into a single record.
// We do not support fragmentation over multiple records.
if (data.byteLength > MAX_RECORD_SIZE) {
throw new TLSError(ALERT_DESCRIPTION.INTERNAL_ERROR);
}
// Flush if we're switching to a different record type.
if (this._pendingRecordType && this._pendingRecordType !== type) {
await this.flush();
}
// Flush if we would overflow the max size of a record.
if (this._pendingRecordBuf !== null) {
if (this._pendingRecordBuf.tell() + data.byteLength > MAX_RECORD_SIZE) {
await this.flush();
}
}
// Start a new pending record if necessary.
// We reserve space at the start of the buffer for the record header,
// which is conveniently always a fixed size.
if (this._pendingRecordBuf === null) {
this._pendingRecordType = type;
this._pendingRecordBuf = new BufferWriter();
this._pendingRecordBuf.incr(RECORD_HEADER_SIZE);
}
this._pendingRecordBuf.writeBytes(data);
}