@Override public byte[] toBytes() throws IOException { ByteWriter bw = new ByteWriter(); bw.writeBytes(background.toBytes()); bw.writeInt(sharps.size()); for (AbsMenuSharp sharp : sharps) { bw.writeInt(sharp.getSharpType()); bw.writeBytes(sharp.toBytes()); } return bw.toByteArray(); }
@Override public void initFromBytes(byte[] bs) throws IOException { ByteReader br = new ByteReader(bs); Background bg = new Background(); bg.initFromBytes(br.readBytes()); int size = br.readInt(); List<AbsMenuSharp> list = new LinkedList<AbsMenuSharp>(); for (int i = 0; i < size; i++) { AbsMenuSharp sharp = AbsSharpFactory.getSharp(br.readInt()); sharp.initFromBytes(br.readBytes()); list.add(sharp); } this.background = bg; this.sharps = list; }