public override int decode(byte[] buffer, int offset)
{
int headerLength;
byte asnType = ParseHeader(buffer, ref offset, out headerLength);
if (asnType != Type)
throw new SnmpException(string.Format("Invalid ASN.1 type. Expected 0x{0:x2} received 0x{1:x2}", Type, asnType));
// verify the length
if ((buffer.Length - offset) < headerLength)
throw new OverflowException("Buffer underflow error");
_oid = new Oid();
offset = _oid.decode(buffer, offset);
int saveOffset = offset;
// Look ahead in the header to see the data type we need to parse
asnType = ParseHeader(buffer, ref saveOffset, out headerLength);
_value = SnmpConstants.GetSyntaxObject(asnType);
if (_value == null)
throw new SnmpDecodingException(String.Format("Invalid ASN.1 type encountered 0x{0:x2}. Unable to continue decoding.", asnType));
offset = _value.decode(buffer, offset);
return offset;
}