ln.snmp/types/Integer.cs

62 lines
1.4 KiB
C#
Raw Normal View History

2019-03-04 06:50:05 +01:00
// /**
// * 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;
2019-03-11 08:57:19 +01:00
using ln.snmp.asn1;
using ln.logging;
using System.Linq;
2019-03-04 06:50:05 +01:00
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;
}
2019-03-04 12:06:45 +01:00
protected Integer(Identifier identifier)
:base(identifier)
{
}
2019-03-11 08:57:19 +01:00
2019-03-04 06:50:05 +01:00
public override byte[] Bytes
{
get => BasicEncodingRules.EncodeInteger(LongValue);
2019-03-11 08:57:19 +01:00
set => LongValue = BasicEncodingRules.DecodeInteger(value.Reverse().ToArray());
2019-03-04 06:50:05 +01:00
}
public override object Value { get => LongValue; set => LongValue = (long)value; }
2019-03-04 12:06:45 +01:00
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;
}
2019-03-04 06:50:05 +01:00
}
2019-03-04 12:06:45 +01:00
2019-03-04 06:50:05 +01:00
}