private void encodeV2Attributes( ByteStringBuilder buffer, Map<AttributeType, List<Attribute>> attributes, EntryEncodeConfig config) throws DirectoryException { int numAttributes = 0; // First count how many attributes are there to encode. for (List<Attribute> attrList : attributes.values()) { for (Attribute a : attrList) { if (a.isVirtual() || a.isEmpty()) { continue; } numAttributes++; } } // Encoded one-to-five byte number of attributes buffer.appendBERLength(numAttributes); if (config.compressAttributeDescriptions()) { for (List<Attribute> attrList : attributes.values()) { for (Attribute a : attrList) { if (a.isVirtual() || a.isEmpty()) { continue; } ByteStringBuilder bsb = new ByteStringBuilder(); config.getCompressedSchema().encodeAttribute(bsb, a); buffer.appendBERLength(bsb.length()); buffer.append(bsb); } } } else { // The attributes will be encoded as a sequence of: // - A UTF-8 byte representation of the attribute name. // - A zero delimiter // - A one-to-five byte number of values for the attribute // - A sequence of: // - A one-to-five byte length for the value // - A UTF-8 byte representation for the value for (List<Attribute> attrList : attributes.values()) { for (Attribute a : attrList) { byte[] nameBytes = getBytes(a.getNameWithOptions()); buffer.append(nameBytes); buffer.append((byte) 0x00); buffer.appendBERLength(a.size()); for (AttributeValue v : a) { buffer.appendBERLength(v.getValue().length()); buffer.append(v.getValue()); } } } } }
/** * The attributes will be encoded as a sequence of: - A UTF-8 byte representation of the attribute * name. - A zero delimiter - A one-to-five byte number of values for the attribute - A sequence * of: - A one-to-five byte length for the value - A UTF-8 byte representation for the value */ private void append(ByteStringBuilder buffer, Map<AttributeType, List<Attribute>> attributes) { for (List<Attribute> attrList : attributes.values()) { for (Attribute a : attrList) { byte[] nameBytes = getBytes(a.getNameWithOptions()); buffer.appendBytes(nameBytes); buffer.appendByte(0x00); buffer.appendBERLength(a.size()); for (ByteString v : a) { buffer.appendBERLength(v.length()); buffer.appendBytes(v); } } } }