import * as I from 'immutable'; import {Packet} from '@avocado/packet'; export class InputPacket extends Packet { static get schema() { return { ...super.schema, data: [ ['string'], ['varint'], ], }; } static fromState(state) { const data = [[], []]; const [actions, values] = data; for (const [action, value] of state.entries()) { actions.push(action); values.push(parseInt(value)); } return new InputPacket(data); } toState() { const [actions, values] = this.data; return I.Map().withMutations((state) => { for (let i = 0; i < actions.length; ++i) { state.set(actions[i], values[i]); } }); } }