2018-02-15 01:25:08 +01:00
|
|
|
import { default as Item } from './Item.js'
|
2018-03-29 11:58:02 +02:00
|
|
|
import { logItemHelper } from '../MessageHandler/messageToString.js'
|
2018-02-15 01:25:08 +01:00
|
|
|
|
2018-02-26 02:18:39 +01:00
|
|
|
export default class ItemFormat extends Item {
|
2018-02-15 01:25:08 +01:00
|
|
|
constructor () {
|
|
|
|
|
super()
|
|
|
|
|
this.key = null
|
|
|
|
|
this.value = null
|
|
|
|
|
}
|
|
|
|
|
_copy (undeleteChildren, copyPosition) {
|
|
|
|
|
let struct = super._copy(undeleteChildren, copyPosition)
|
|
|
|
|
struct.key = this.key
|
|
|
|
|
struct.value = this.value
|
|
|
|
|
return struct
|
|
|
|
|
}
|
|
|
|
|
get _length () {
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
get _countable () {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
_fromBinary (y, decoder) {
|
2018-02-26 02:18:39 +01:00
|
|
|
const missing = super._fromBinary(y, decoder)
|
2018-02-15 01:25:08 +01:00
|
|
|
this.key = decoder.readVarString()
|
2018-02-26 02:18:39 +01:00
|
|
|
this.value = JSON.parse(decoder.readVarString())
|
2018-02-15 01:25:08 +01:00
|
|
|
return missing
|
|
|
|
|
}
|
|
|
|
|
_toBinary (encoder) {
|
|
|
|
|
super._toBinary(encoder)
|
|
|
|
|
encoder.writeVarString(this.key)
|
2018-02-26 02:18:39 +01:00
|
|
|
encoder.writeVarString(JSON.stringify(this.value))
|
2018-02-15 01:25:08 +01:00
|
|
|
}
|
2018-03-29 11:58:02 +02:00
|
|
|
/**
|
|
|
|
|
* Transform this YXml Type to a readable format.
|
|
|
|
|
* Useful for logging as all Items and Delete implement this method.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
2018-02-15 01:25:08 +01:00
|
|
|
_logString () {
|
2018-03-29 11:58:02 +02:00
|
|
|
return logItemHelper('ItemFormat', this, `key:${JSON.stringify(this.key)},value:${JSON.stringify(this.value)}`)
|
2018-02-15 01:25:08 +01:00
|
|
|
}
|
|
|
|
|
}
|