asnencoder.java

来自「opennms得相关源码 请大家看看」· Java 代码 · 共 433 行 · 第 1/2 页

JAVA
433
字号
//// This file is part of the OpenNMS(R) Application.//// OpenNMS(R) is Copyright (C) 2002-2003 The OpenNMS Group, Inc.  All rights reserved.// OpenNMS(R) is a derivative work, containing both original code, included code and modified// code that was published under the GNU General Public License. Copyrights for modified // and included code are below.//// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.//// Copyright (C) 1999-2001 Oculan Corp.  All rights reserved.//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//// For more information contact://      OpenNMS Licensing       <license@opennms.org>//      http://www.opennms.org///      http://www.opennms.com///// Tab Size = 8//// AsnEncoder.java,v 1.1.1.1 2001/11/11 17:27:23 ben Exp//package org.opennms.protocols.snmp.asn1;import java.math.BigInteger;/** * The AsnEncoder interface defines the contract that objects for * encoding/decoding ASN.1 SNMP values must fulfill. The encoder must be able to * encode and decode integers (unsigned and signed), object identifier, strings, * and null values. To support the SNMPv2 the AsnEncoder class must also support * encoding/decoding 64-bit integers. Currently the AsnEncoder interface only * supports SNMPv1 types. *  * @author <a href="http://www.opennms.org">OpenNMS </a> * @author <a href="mailto:weave@oculan.com>Brian Weaver </a> * @version 1.1.1.1 */public interface AsnEncoder {    /**     *      * The buildLength() method is used to encode an ASN.1 length into the     * specified byte buffer. The encoding used is dependant on the implementor     * of the interface.     *      * @param buf     *            The output buffer of encoded bytes.     * @param startOffset     *            The offset from the start of the buffer where the method     *            should start writing the encoded data.     * @param asnLength     *            The length to be encoded.     *      * @return Returns the new offset for the next encoding routine. If the     *         startOffset is subtracted from the return value then the length     *         of the encoded data can be determined.     *      * @exception AsnEncodingException     *                Thrown if an error occurs encoding the datatype.     *      */    public int buildLength(byte[] buf, int startOffset, int asnLength) throws AsnEncodingException;    /**     *      * The parseLength() method is used to decode an ASN.1 length from the     * specified buffer. The encoding used is depandant on the implemetor of the     * interface.     *      * @param buf     *            The input buffer     * @param startOffset     *            The offset to start decoding in the buffer     *      * @return Returns an Object array that contains the new offset and the     *         decoded length. The first object is an Integer object and     *         contains the new offset for the next object in buf. The second     *         object is an Integer and contains the actual decoded length.     *      * @exception AsnDecodingException     *                Thrown if an error occurs decoding the buffer.     */    public Object[] parseLength(byte[] buf, int startOffset) throws AsnDecodingException;    /**     *      * The buildHeader() method is used to encode an ASN.1 header into the     * specified byte buffer. The encoding used is dependant on the implementor     * of the interface.     *      * @param buf     *            The output buffer of encoded bytes.     * @param startOffset     *            The offset from the start of the buffer where the method     *            should start writing the encoded data.     * @param asnType     *            The ASN.1 type to place in the buffer     * @param asnLength     *            The length to be encoded.     *      * @return Returns the new offset for the next encoding routine. If     *         startOffset is subtracted from the return value then the length     *         of the encoded data can be determined.     *      * @exception AsnEncodingException     *                Thrown if an error occurs encoding the datatype.     *      */    public int buildHeader(byte[] buf, int startOffset, byte asnType, int asnLength) throws AsnEncodingException;    /**     *      * The parseHeader() method is used to decode an ASN.1 header from the     * specified buffer. The encoding used is depandant on the implemetor of the     * interface.     *      * @param buf     *            The input buffer     * @param startOffset     *            The offset to start decoding in the buffer     *      * @return Returns an Object array that contains the new offset, ASN.1 type,     *         and decoded length. The first object is an Integer object and     *         contains the new offset for the next object in buf. The second     *         object is a Byte object that represents the decoded ASN.1 Type.     *         The third object is an Integer and contains the actual decoded     *         length.     *      * @exception AsnDecodingException     *                Thrown if an error occurs decoding the buffer.     */    public Object[] parseHeader(byte[] buf, int startOffset) throws AsnDecodingException;    /**     *      * The buildInteger32() method is used to encode an ASN.1 32-bit signed     * integer into the specified byte buffer. The encoding used is dependant on     * the implementor of the interface.     *      * @param buf     *            The output buffer of encoded bytes.     * @param startOffset     *            The offset from the start of the buffer where the method     *            should start writing the encoded data.     * @param asnType     *            The ASN.1 type to place in the buffer     * @param asnInt32     *            The 32-bit signed integer to encode.     *      * @return Returns the new offset for the next encoding routine. If     *         startOffset is subtracted from the return value then the length     *         of the encoded data can be determined.     *      * @exception AsnEncodingException     *                Thrown if an error occurs encoding the datatype.     *      */    public int buildInteger32(byte[] buf, int startOffset, byte asnType, int asnInt32) throws AsnEncodingException;    /**     *      * The parseInteger32() method is used to decode an ASN.1 32-bit signed     * integer from the specified buffer. The encoding used is depandant on the     * implemetor of the interface.     *      * @param buf     *            The input buffer     * @param startOffset     *            The offset to start decoding in the buffer     *      * @return Returns an Object array that contains the new offset, ASN.1 type,     *         and value. The first object is an Integer object and contains the     *         new offset for the next object in buf. The second object is a     *         Byte object that represents the decoded ASN.1 Type. The third     *         object is an Integer and contains the actual decoded value.     *      * @exception AsnDecodingException     *                Thrown if an error occurs decoding the buffer.     */    public Object[] parseInteger32(byte[] buf, int startOffset) throws AsnDecodingException;    /**     *      * The buildUInteger32() method is used to encode an ASN.1 32-bit unsigned     * integer into the specified byte buffer. The encoding used is dependant on     * the implementor of the interface.     *      * @param buf     *            The output buffer of encoded bytes.     * @param startOffset     *            The offset from the start of the buffer where the method     *            should start writing the encoded data.     * @param asnType     *            The ASN.1 type to place in the buffer     * @param asnUInt32     *            The 32-bit unsigned integer to encode.     *      * @return Returns the new offset for the next encoding routine. If     *         startOffset is subtracted from the return value then the length     *         of the encoded data can be determined.     *      * @exception AsnEncodingException     *                Thrown if an error occurs encoding the datatype.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?