/** * Returns a {@code CompactId} constructed from the ID's external format contained in the * specified message buffer. * * @param buf a message buffer containing the external format of a {@code CompactId} * @return a {@code CompactId} constructed from the external format in the given message buffer * @throws IllegalArgumentException if the external format contained in the message buffer is * malformed or unsupported */ public static CompactId getCompactId(MessageBuffer buf) { int bufSize = buf.limit() - buf.position(); if (bufSize == 0) { throw new IllegalArgumentException("empty buffer"); } byte lengthByte = buf.getByte(); int size = getExternalFormByteCount(lengthByte); if (bufSize < size) { throw new IllegalArgumentException("buffer size insufficient"); } byte[] externalForm = new byte[size]; externalForm[0] = lengthByte; for (int i = 1; i < size; i++) { externalForm[i] = buf.getByte(); } return CompactId.fromExternalForm(externalForm); }
/** * Puts the external form of this {@code CompactId} in the specified message buffer. * * @param buf a message buffer * @throws IllegalArgumentException if the message buffer size is insufficient */ public void putCompactId(MessageBuffer buf) { if (buf.capacity() - buf.position() < externalForm.length) { throw new IllegalArgumentException("buffer size insufficient"); } buf.putBytes(externalForm); }