当前位置: 首页>>代码示例>>C#>>正文


C# Integer32.decode方法代码示例

本文整理汇总了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;
 }
开发者ID:griffina,项目名称:SnmpSharpNet,代码行数:42,代码来源:SnmpPacket.cs


注:本文中的Integer32.decode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。