/** * Serialize all the metadata entries. * * <p>It produces serialized names and values interleaved. result[i*2] are names, while * result[i*2+1] are values. * * <p>Names are ASCII string bytes that contains only the characters listed in the class comment * of {@link Key}. If the name ends with {@code "-bin"}, the value can be raw binary. Otherwise, * the value must contain only characters listed in the class comments of {@link AsciiMarshaller} * * <p>The returned individual byte arrays <em>must not</em> be modified. However, the top level * array may be modified. * * <p>This method is intended for transport use only. */ @Nullable byte[][] serialize() { if (len() == cap()) { return namesAndValues; } byte[][] serialized = new byte[len()][]; System.arraycopy(namesAndValues, 0, serialized, 0, len()); return serialized; }
private void maybeExpand() { if (len() == 0 || len() == cap()) { expand(Math.max(len() * 2, 8)); } }
/** * Serialize all the metadata entries. * * <p>It produces serialized names and values interleaved. result[i*2] are names, while * result[i*2+1] are values. * * <p>Names are ASCII string bytes that contains only the characters listed in the class comment * of {@link Key}. If the name ends with {@code "-bin"}, the value can be raw binary. Otherwise, * the value must contain only characters listed in the class comments of {@link AsciiMarshaller} * * <p>The returned individual byte arrays <em>must not</em> be modified. However, the top level * array may be modified. * * <p>This method is intended for transport use only. */ @Nullable byte[][] serialize() { if (len() == cap()) { return namesAndValues; } byte[][] serialized = new byte[len()][]; System.arraycopy(namesAndValues, 0, serialized, 0, len()); return serialized; }
private void maybeExpand() { if (len() == 0 || len() == cap()) { expand(Math.max(len() * 2, 8)); } }
/** * Perform a simple merge of two sets of metadata. * * <p>This is a purely additive operation, because a single key can be associated with multiple * values. */ public void merge(Metadata other) { if (other.isEmpty()) { return; } int remaining = cap() - len(); if (isEmpty() || remaining < other.len()) { expand(len() + other.len()); } System.arraycopy(other.namesAndValues, 0, namesAndValues, len(), other.len()); size += other.size; }
/** * Perform a simple merge of two sets of metadata. * * <p>This is a purely additive operation, because a single key can be associated with multiple * values. */ public void merge(Metadata other) { if (other.isEmpty()) { return; } int remaining = cap() - len(); if (isEmpty() || remaining < other.len()) { expand(len() + other.len()); } System.arraycopy(other.namesAndValues, 0, namesAndValues, len(), other.len()); size += other.size; }