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 ItemJSON extends Item {
|
|
|
|
|
constructor () {
|
|
|
|
|
super()
|
|
|
|
|
this._content = null
|
|
|
|
|
}
|
|
|
|
|
get _length () {
|
|
|
|
|
return this._content.length
|
|
|
|
|
}
|
|
|
|
|
_fromBinary (y, decoder) {
|
|
|
|
|
let missing = super._fromBinary(y, decoder)
|
|
|
|
|
let len = decoder.readVarUint()
|
|
|
|
|
this._content = new Array(len)
|
|
|
|
|
for (let i = 0; i < len; i++) {
|
2017-10-19 17:36:28 +02:00
|
|
|
const ctnt = decoder.readVarString()
|
|
|
|
|
this._content[i] = JSON.parse(ctnt)
|
2017-10-11 03:41:54 +02:00
|
|
|
}
|
|
|
|
|
return missing
|
|
|
|
|
}
|
2017-10-16 04:53:12 +02:00
|
|
|
_toBinary (encoder) {
|
|
|
|
|
super._toBinary(encoder)
|
2017-10-11 03:41:54 +02:00
|
|
|
let len = this._content.length
|
|
|
|
|
encoder.writeVarUint(len)
|
|
|
|
|
for (let i = 0; i < len; i++) {
|
|
|
|
|
encoder.writeVarString(JSON.stringify(this._content[i]))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_logString () {
|
|
|
|
|
let s = super._logString()
|
|
|
|
|
return 'ItemJSON: ' + 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 ItemJSON()
|
|
|
|
|
item._content = this._content.splice(diff)
|
|
|
|
|
splitHelper(y, this, item, diff)
|
|
|
|
|
return item
|
|
|
|
|
}
|
2017-10-11 03:41:54 +02:00
|
|
|
}
|