ln.snmp/types/SnmpMessage.cs

49 lines
1.3 KiB
C#

// /**
// * File: SnmpMessage.cs
// * Author: haraldwolff
// *
// * This file and it's content is copyrighted by the Author and / or copyright holder.
// * Any use wihtout proper permission is illegal and may lead to legal actions.
// *
// *
// **/
using System;
using ln.snmp.asn1;
namespace ln.snmp.types
{
public abstract class SnmpMessage : AbstractSequence
{
public SnmpVersion SnmpVersion { get; }
public abstract int MessageID { get; set; }
public SnmpMessage(SnmpVersion snmpVersion)
: base(new Identifier(IdentifierClass.UNIVERSAL, true, 0x10))
{
SnmpVersion = snmpVersion;
}
public override void Add(Variable item) => throw new NotImplementedException();
public override void Remove(Variable item) => throw new NotImplementedException();
public static implicit operator SnmpMessage(ASN1Value asn)
{
Integer snmpVersion = (Integer)(Variable)asn.Items[0];
switch (snmpVersion.LongValue)
{
case 0:
return new SnmpV1Message(asn);
case 1:
return new SnmpV2Message(asn);
case 3:
return new USMMessage(asn);
}
throw new ArgumentException();
}
}
}