Class LdapEncoder
- java.lang.Object
-
- org.apache.directory.api.ldap.codec.api.LdapEncoder
-
public class LdapEncoder extends Object
LDAP BER encoder.- Author:
- Apache Directory Project
-
-
Constructor Summary
Constructors Constructor Description LdapEncoder(LdapApiService codec)
Creates an instance of Ldap message encoder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static int
computeControlLength(Control control)
Compute the control's encoded lengthstatic int
computeReferralLength(Referral referral)
Compute the referral's encoded lengthstatic ByteBuffer
encodeControl(ByteBuffer buffer, Control control)
Encode a control to a byte[]ByteBuffer
encodeMessage(Message message)
Generate the PDU which contains the encoded object.static void
encodeReferral(ByteBuffer buffer, Referral referral)
Encode the Referral message to a PDU.
-
-
-
Constructor Detail
-
LdapEncoder
public LdapEncoder(LdapApiService codec)
Creates an instance of Ldap message encoder- Parameters:
codec
- The Codec service to use to handle Controls and extended operations, plus to get access to the underlying services.
-
-
Method Detail
-
computeControlLength
public static int computeControlLength(Control control)
Compute the control's encoded length- Parameters:
control
- The control to compute- Returns:
- the encoded control length
-
encodeControl
public static ByteBuffer encodeControl(ByteBuffer buffer, Control control) throws EncoderException
Encode a control to a byte[]- Parameters:
buffer
- The buffer that will contain the encoded controlcontrol
- The control to encode- Returns:
- The control encoded in a byte[]
- Throws:
EncoderException
- If the encoding failed
-
encodeMessage
public ByteBuffer encodeMessage(Message message) throws EncoderException
Generate the PDU which contains the encoded object. The generation is done in two phases : - first, we compute the length of each part and the global PDU length - second, we produce the PDU.0x30 L1 | +--> 0x02 L2 MessageId +--> ProtocolOp +--> Controls L2 = Length(MessageId) L1 = Length(0x02) + Length(L2) + L2 + Length(ProtocolOp) + Length(Controls) LdapMessageLength = Length(0x30) + Length(L1) + L1
- Parameters:
message
- The message to encode- Returns:
- A ByteBuffer that contains the PDU
- Throws:
EncoderException
- If anything goes wrong.
-
encodeReferral
public static void encodeReferral(ByteBuffer buffer, Referral referral) throws EncoderException
Encode the Referral message to a PDU.- Parameters:
buffer
- The buffer where to put the PDUreferral
- The referral to encode- Throws:
EncoderException
- If the encoding failed
-
computeReferralLength
public static int computeReferralLength(Referral referral)
Compute the referral's encoded length- Parameters:
referral
- The referral to encode- Returns:
- The length of the encoded PDU
-
-