public void serialize(ReusableBuffer rb) { rb.put(CURRENT_VERSION); rb.putString(uuid); rb.putLong(getVersion()); for (KeyValuePair kvp : configurationParameter) { rb.putString(kvp.getKey()); rb.putString(kvp.getValue()); } }
public int getSize() { final int BYTE_SIZE = Byte.SIZE / 8; final int INT_SIZE = Integer.SIZE / 8; final int LONG_SIZE = Long.SIZE / 8; // length of the uuid + 1*INT_SIZE for the uuid datatype int size = getUuid().length() + INT_SIZE; // +size of the version size += LONG_SIZE; // +size of the CURRENT_VERSION size += BYTE_SIZE; // +size of the data HashMap size += (getData().size() * INT_SIZE * 2); // +size of the values in the HashMap for (KeyValuePair kvp : configurationParameter) { size += kvp.getKey().length() + kvp.getValue().length(); } return size; }
public ConfigurationRecord(ReusableBuffer rb) throws IOException { byte recVersion = rb.get(); if (recVersion == 1) { this.uuid = rb.getString(); this.version = rb.getLong(); this.configurationParameter = new Vector<KeyValuePair>(); while (rb.remaining() != 0) { configurationParameter.add( KeyValuePair.newBuilder().setKey(rb.getString()).setValue(rb.getString()).build()); } } else { throw new IOException("don't know how to handle version " + recVersion); } }