decode() публичный Метод

Decode sequence from the byte array. Returned offset value is advanced by the size of the sequence header.
public decode ( byte buffer, int offset ) : int
buffer byte Source data buffer
offset int Offset within the buffer to start parsing from
Результат int
Пример #1
0
        /// <summary>
        /// Decode SNMP packet header. This class decodes the initial sequence and SNMP protocol version
        /// number.
        /// </summary>
        /// <param name="buffer">BER encoded SNMP packet</param>
        /// <param name="length">Packet length</param>
        /// <returns>Offset position after the initial sequence header and protocol version value</returns>
        public virtual int decode(byte[] buffer, int length)
        {
            int offset = 0;

            if (length < 2)
            {
                // we need at least 2 bytes
                throw new OverflowException("Packet too small.");
            }
            // make sure you get the right length buffer to be able to check for over/under flow errors
            MutableByte buf = new MutableByte(buffer, length);
            Sequence    seq = new Sequence();

            offset = seq.decode(buf, offset);
            offset = _protocolVersion.decode(buf, offset);
            return(offset);
        }
Пример #2
0
        /// <summary>
        ///     Decode SNMP packet header. This class decodes the initial sequence and SNMP protocol version
        ///     number.
        /// </summary>
        /// <param name="buffer">BER encoded SNMP packet</param>
        /// <param name="length">Packet length</param>
        /// <returns>Offset position after the initial sequence header and protocol version value</returns>
        /// <exception cref="SnmpDecodingException">
        ///     Thrown when invalid sequence type is found at the start of the SNMP packet
        ///     being decoded
        /// </exception>
        public virtual int decode(byte[] buffer, int length)
        {
            var offset = 0;

            if (length < 2)
            {
                throw new OverflowException("Packet too small.");
            }
            // make sure you get the right length buffer to be able to check for over/under flow errors
            var buf = new MutableByte(buffer, length);
            var seq = new Sequence();

            offset = seq.decode(buf, offset);
            if (seq.Type != SnmpConstants.SMI_SEQUENCE)
            {
                throw new SnmpDecodingException("Invalid sequence type at the start of the SNMP packet.");
            }
            offset = _protocolVersion.decode(buf, offset);
            return(offset);
        }
Пример #3
0
 /// <summary>
 /// Decode SNMP packet header. This class decodes the initial sequence and SNMP protocol version
 /// number.
 /// </summary>
 /// <param name="buffer">BER encoded SNMP packet</param>
 /// <param name="length">Packet length</param>
 /// <returns>Offset position after the initial sequence header and protocol version value</returns>
 /// <exception cref="SnmpDecodingException">Thrown when invalid sequence type is found at the start of the SNMP packet being decoded</exception>
 public virtual int decode(byte[] buffer, int length)
 {
     int offset = 0;
     if (length < 2)
     {
         // we need at least 2 bytes
         throw new OverflowException("Packet too small.");
     }
     // make sure you get the right length buffer to be able to check for over/under flow errors
     MutableByte buf = new MutableByte(buffer, length);
     Sequence seq = new Sequence();
     offset = seq.decode(buf, offset);
     if( seq.Type != SnmpConstants.SMI_SEQUENCE )
         throw new SnmpDecodingException("Invalid sequence type at the start of the SNMP packet.");
     offset = _protocolVersion.decode(buf, offset);
     return offset;
 }