@Override public byte[] encode() { final byte[] name = StringUtils.toUTF8(this.m_inviterName); final byte[] groupName = StringUtils.toUTF8(this.m_groupName); final int sizeDatas = 3 + name.length + 1 + groupName.length + 8; final ByteBuffer buffer = ByteBuffer.allocate(sizeDatas); buffer.put(this.m_groupType); buffer.put((byte) (this.m_invitationAccepted ? 1 : 0)); buffer.put((byte) name.length); buffer.put(name); buffer.put((byte) groupName.length); buffer.put(groupName); buffer.putLong(this.m_inviterId); if (this.m_sendToGlobalServer) { return this.addClientHeader((byte) 6, buffer.array()); } return this.addClientHeader((byte) 2, buffer.array()); }
@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(); }