mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-25 07:32:27 +01:00
52 lines
1.1 KiB
JavaScript
52 lines
1.1 KiB
JavaScript
import {Settings} from "./Settings";
|
|
|
|
function NetscriptPort() {
|
|
this.data = [];
|
|
}
|
|
|
|
NetscriptPort.prototype.write = function(data) {
|
|
this.data.push(data);
|
|
if (this.data.length > Settings.MaxPortCapacity) {
|
|
return this.data.shift();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
NetscriptPort.prototype.tryWrite = function(data) {
|
|
if (this.data.length >= Settings.MaxPortCapacity) {
|
|
return false;
|
|
}
|
|
this.data.push(data);
|
|
return true;
|
|
}
|
|
|
|
NetscriptPort.prototype.read = function() {
|
|
if (this.data.length === 0) {
|
|
return "NULL PORT DATA";
|
|
}
|
|
return this.data.shift();
|
|
}
|
|
|
|
NetscriptPort.prototype.peek = function() {
|
|
if (this.data.length === 0) {
|
|
return "NULL PORT DATA";
|
|
} else {
|
|
var foo = this.data.slice();
|
|
return foo[0];
|
|
}
|
|
}
|
|
|
|
NetscriptPort.prototype.full = function() {
|
|
return this.data.length == Settings.MaxPortCapacity;
|
|
}
|
|
|
|
NetscriptPort.prototype.empty = function() {
|
|
return this.data.length === 0;
|
|
}
|
|
|
|
NetscriptPort.prototype.clear = function() {
|
|
this.data.length = 0;
|
|
}
|
|
|
|
export {NetscriptPort};
|