ln.snmp/types/Integer.cs

62 lines
1.4 KiB
C#

// /**
// * File: Integer.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;
using ln.logging;
using System.Linq;
namespace ln.snmp.types
{
public class Integer : Variable
{
public long LongValue { get; set; }
public Integer()
:base(new Identifier(IdentifierClass.UNIVERSAL, false, 0x02))
{
}
public Integer(long value)
:this()
{
LongValue = value;
}
protected Integer(Identifier identifier)
:base(identifier)
{
}
public override byte[] Bytes
{
get => BasicEncodingRules.EncodeInteger(LongValue);
set => LongValue = BasicEncodingRules.DecodeInteger(value.Reverse().ToArray());
}
public override object Value { get => LongValue; set => LongValue = (long)value; }
public override string ToString()
{
return String.Format("[Integer LongValue={0}]", LongValue);
}
public static implicit operator int(Integer integer)
{
return (int)integer.LongValue;
}
public static implicit operator long(Integer integer)
{
return integer.LongValue;
}
}
}