2017-10-16 04:53:12 +02:00
|
|
|
import { splitHelper, default as Item } from './Item.js'
|
2017-10-11 03:41:54 +02:00
|
|
|
|
|
|
|
|
export default class ItemString extends Item {
|
|
|
|
|
constructor () {
|
|
|
|
|
super()
|
|
|
|
|
this._content = null
|
|
|
|
|
}
|
|
|
|
|
get _length () {
|
|
|
|
|
return this._content.length
|
|
|
|
|
}
|
|
|
|
|
_fromBinary (y, decoder) {
|
|
|
|
|
let missing = super._fromBinary(y, decoder)
|
|
|
|
|
this._content = decoder.readVarString()
|
|
|
|
|
return missing
|
|
|
|
|
}
|
2017-10-16 04:53:12 +02:00
|
|
|
_toBinary (encoder) {
|
|
|
|
|
super._toBinary(encoder)
|
2017-10-11 03:41:54 +02:00
|
|
|
encoder.writeVarString(this._content)
|
|
|
|
|
}
|
|
|
|
|
_logString () {
|
|
|
|
|
let s = super._logString()
|
|
|
|
|
return 'ItemString: ' + s
|
|
|
|
|
}
|
2017-10-16 04:53:12 +02:00
|
|
|
_splitAt (y, diff) {
|
|
|
|
|
if (diff === 0) {
|
|
|
|
|
return this
|
|
|
|
|
} else if (diff >= this._length) {
|
|
|
|
|
return this._right
|
|
|
|
|
}
|
|
|
|
|
let item = new ItemString()
|
|
|
|
|
item._content = this._content.slice(diff)
|
|
|
|
|
this._content = this._content.slice(0, diff)
|
|
|
|
|
splitHelper(y, this, item, diff)
|
|
|
|
|
return item
|
|
|
|
|
}
|
2017-10-11 03:41:54 +02:00
|
|
|
}
|