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 */ 020package org.apache.directory.shared.asn1; 021 022 023import java.nio.ByteBuffer; 024 025 026/** 027 * An abstract class which implements basic TLV operations. 028 * 029 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 030 */ 031public interface Asn1Object 032{ 033 /** 034 * Get the current object length, which is the sum of all inner length 035 * already decoded. 036 * 037 * @return The current object's length 038 */ 039 int getCurrentLength(); 040 041 042 /** 043 * Compute the object length, which is the sum of all inner length. 044 * 045 * @return The object's computed length 046 */ 047 int computeLength(); 048 049 050 /** 051 * Encode the object to a PDU. 052 * 053 * @param buffer The buffer where to put the PDU 054 * @return The PDU. 055 * @throws EncoderException if the buffer can't be encoded 056 */ 057 ByteBuffer encode( ByteBuffer buffer ) throws EncoderException; 058 059 060 /** 061 * Get the expected object length. 062 * 063 * @return The expected object's length 064 */ 065 int getExpectedLength(); 066 067 068 /** 069 * Add a length to the object 070 * 071 * @param length The length to add. 072 * @throws DecoderException Thrown if the current length exceed the expected length 073 */ 074 void addLength( int length ) throws DecoderException; 075 076 077 /** 078 * Set the expected length 079 * 080 * @param expectedLength The expectedLength to set. 081 */ 082 void setExpectedLength( int expectedLength ); 083 084 085 /** 086 * Set the current length 087 * 088 * @param currentLength The currentLength to set. 089 */ 090 void setCurrentLength( int currentLength ); 091 092 093 /** 094 * Get the parent 095 * 096 * @return Returns the parent. 097 */ 098 Asn1Object getParent(); 099}