@Override public void build(final ByteBuffer bb, final int id, final short version) { this.setGlobalId(id); if (version == 1) { this.m_id = bb.getInt(); this.m_type = bb.get(); this.m_userType = bb.get(); this.m_autoTrigger = (bb.get() == 1); this.m_isChallenge = (bb.get() == 1); this.m_isChaos = (bb.get() == 1); this.m_duration = bb.getShort(); this.m_minUsers = bb.getShort(); this.m_maxUsers = bb.getShort(); final long time = bb.getLong(); if (time != 0L) { this.m_expirationDate = GameDate.fromLong(time); } else { this.m_expirationDate = null; } try { final byte[] bytes = new byte[bb.getInt()]; bb.get(bytes); this.m_params = new String(bytes, "UTF-8").intern(); } catch (UnsupportedEncodingException e) { ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e); } try { final int mappingLen = bb.getInt(); this.m_varMapping = new String[mappingLen]; for (int i = 0; i < mappingLen; ++i) { final byte[] bytes2 = new byte[bb.getInt()]; bb.get(bytes2); this.m_varMapping[i] = new String(bytes2, "UTF-8").intern(); } } catch (UnsupportedEncodingException e) { ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e); } try { final byte[] bytes = new byte[bb.getInt()]; bb.get(bytes); this.m_joinCriterion = new String(bytes, "UTF-8").intern(); final byte[] rewardEligibilityCriterion = new byte[bb.getInt()]; bb.get(rewardEligibilityCriterion); this.m_rewardEligibilityCriterion = new String(rewardEligibilityCriterion, "UTF-8").intern(); } catch (UnsupportedEncodingException e) { ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e); } for (int glen = bb.getInt(), i = 0; i < glen; ++i) { final byte[] gdata = new byte[bb.getInt()]; bb.get(gdata); final ActionGroupStorable g = new ActionGroupStorable(); g.unserialise(gdata); this.m_actionGroups.add(g); } for (int rlen = bb.getInt(), j = 0; j < rlen; ++j) { final byte[] rdata = new byte[bb.getInt()]; bb.get(rdata); final RewardStorable r = new RewardStorable(); r.unserialise(rdata); this.m_rewards.add(r); } } else { ScenarioBinaryStorable.m_logger.error( (Object) "Tentative de d\u00e9s\u00e9rialisation d'un objet avec une version non prise en charge"); } }
@Override public byte[] getBinaryData() { final ArrayList<byte[]> binGroups = new ArrayList<byte[]>(this.m_actionGroups.size()); final ArrayList<byte[]> binRewars = new ArrayList<byte[]>(this.m_rewards.size()); int presize = 0; presize += 4; try { for (final String var : this.m_varMapping) { presize += 4 + var.getBytes("UTF-8").length; } } catch (Exception e) { ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e); } try { presize += 8; presize += ((this.m_joinCriterion != null) ? this.m_joinCriterion.getBytes("UTF-8").length : 0); presize += ((this.m_rewardEligibilityCriterion != null) ? this.m_rewardEligibilityCriterion.getBytes("UTF-8").length : 0); } catch (Exception e) { ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e); } for (final ActionGroupStorable g : this.m_actionGroups) { final byte[] bin = g.serialize(); presize += bin.length + 4; binGroups.add(bin); } for (final RewardStorable r : this.m_rewards) { final byte[] bin = r.serialize(); presize += bin.length + 4; binRewars.add(bin); } try { presize += 4; presize += ((this.m_params != null) ? this.m_params.getBytes("UTF-8").length : 0); } catch (Exception e) { ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e); } final ByteBuffer bb = ByteBuffer.allocate(31 + presize); bb.putInt(this.m_id); bb.put(this.m_type); bb.put(this.m_userType); bb.put((byte) (this.m_autoTrigger ? 1 : 0)); bb.put((byte) (this.m_isChallenge ? 1 : 0)); bb.put((byte) (this.m_isChaos ? 1 : 0)); bb.putShort(this.m_duration); bb.putShort(this.m_minUsers); bb.putShort(this.m_maxUsers); if (this.m_expirationDate != null) { bb.putLong(this.m_expirationDate.toLong()); } else { bb.putLong(0L); } try { if (this.m_params != null) { final byte[] bytes = this.m_params.getBytes("UTF-8"); bb.putInt(bytes.length); bb.put(bytes); } else { bb.putInt(0); } } catch (Exception e2) { ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e2); } try { bb.putInt(this.m_varMapping.length); for (final String var2 : this.m_varMapping) { final byte[] bytes2 = var2.getBytes("UTF-8"); bb.putInt(bytes2.length); bb.put(bytes2); } } catch (Exception e2) { ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e2); } try { if (this.m_joinCriterion != null) { final byte[] bytes = this.m_joinCriterion.getBytes("UTF-8"); bb.putInt(bytes.length); bb.put(bytes); } else { bb.putInt(0); } if (this.m_rewardEligibilityCriterion != null) { final byte[] bytes = this.m_rewardEligibilityCriterion.getBytes("UTF-8"); bb.putInt(bytes.length); bb.put(bytes); } else { bb.putInt(0); } } catch (Exception e2) { ScenarioBinaryStorable.m_logger.error((Object) "Exception", (Throwable) e2); } bb.putInt(binGroups.size()); for (final byte[] gdata : binGroups) { bb.putInt(gdata.length); bb.put(gdata); } bb.putInt(binRewars.size()); for (final byte[] rdata : binRewars) { bb.putInt(rdata.length); bb.put(rdata); } return bb.array(); }