本文整理汇总了C#中Integer32.decode方法的典型用法代码示例。如果您正苦于以下问题:C# Integer32.decode方法的具体用法?C# Integer32.decode怎么用?C# Integer32.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Integer32
的用法示例。
在下文中一共展示了Integer32.decode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetProtocolVersion
/// <summary>
/// Get SNMP protocol version from the packet. This routine does not verify if version number is valid. Caller
/// should verify that returned value represents a valid SNMP protocol version number.
///
/// <code>
/// int protocolVersion = Packet.GetProtocolVersion(inPacket, inLength);
/// if( protocolVersion != -1 )
/// {
/// if( protocolVersion == SnmpConstants.SNMPV1 || protocolVersion == SnmpConstants.SNMPV2 || protocolVersion == SnmpConstants.SNMPV3 )
/// {
/// // do something
/// }
/// else
/// {
/// Console.WriteLine("Invalid SNMP protocol version.");
/// }
/// }
/// else
/// {
/// Console.WriteLine("Invalid SNMP packet.");
/// }
/// </code>
/// </summary>
/// <param name="buffer">BER encoded SNMP packet</param>
/// <param name="bufferLength">Length of the BER encoded packet</param>
/// <returns>Returns SNMP protocol version, if packet is not valid returned value is -1.</returns>
/// <exception cref="SnmpDecodingException">Thrown when invalid sequence type is found at the start of the SNMP packet being decoded</exception>
public static int GetProtocolVersion(byte[] buffer, int bufferLength)
{
int offset = 0;
int length = 0;
byte asnType = AsnType.ParseHeader(buffer, ref offset, out length);
if ((offset + length) > bufferLength)
{
return -1; // This is not a valid packet
}
if( asnType != SnmpConstants.SMI_SEQUENCE )
throw new SnmpDecodingException("Invalid sequence type at the start of the SNMP packet.");
Integer32 version = new Integer32();
offset = version.decode(buffer, offset);
return version.Value;
}