001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020 package org.apache.directory.shared.ldap.codec.controls;
021
022 import java.nio.ByteBuffer;
023
024 import org.apache.directory.shared.asn1.codec.EncoderException;
025
026 /**
027 * Define the transform method to be implemented by all the codec Controls
028 *
029 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
030 * @version $Rev$, $Date$
031 */
032 public interface CodecControl
033 {
034 /**
035 * Generate the PDU which contains the Control.
036 * <pre>
037 * Control :
038 *
039 * 0x30 LL
040 * 0x04 LL type
041 * [0x01 0x01 criticality]
042 * [0x04 LL value]
043 * </pre>
044 * @param buffer The encoded PDU
045 * @return A ByteBuffer that contaons the PDU
046 * @throws EncoderException If anything goes wrong.
047 */
048 ByteBuffer encode( ByteBuffer buffer ) throws EncoderException;
049
050
051 /**
052 * Compute the Control length
053 * <pre>
054 * Control :
055 *
056 * 0x30 L1
057 * |
058 * +--> 0x04 L2 controlType
059 * [+--> 0x01 0x01 criticality]
060 * [+--> 0x04 L3 controlValue]
061 *
062 * Control length = Length(0x30) + length(L1)
063 * + Length(0x04) + Length(L2) + L2
064 * [+ Length(0x01) + 1 + 1]
065 * [+ Length(0x04) + Length(L3) + L3]
066 * </pre>
067 */
068 int computeLength();
069
070 /**
071 * Get the associated decoder
072 *
073 * @return The Control decoder
074 */
075 ControlDecoder getDecoder();
076 }