ln.snmp/types/OctetString.cs

68 lines
1.6 KiB
C#
Raw Normal View History

2019-03-04 06:50:05 +01:00
// /**
// * File: OctetString.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 System.Text;
2019-03-11 08:57:19 +01:00
using ln.snmp.asn1;
2019-03-04 06:50:05 +01:00
namespace ln.snmp.types
{
public class OctetString : Variable
{
2019-03-11 08:57:19 +01:00
public override byte[] Bytes { get; set; }
public string StringValue {
get => Encoding.UTF8.GetString(Bytes);
set => Bytes = Encoding.UTF8.GetBytes(value);
}
public char[] Characters
{
get => StringValue.ToCharArray();
set => StringValue = new string(value);
}
public override object Value { get => Bytes; set => Bytes = (byte[])value; }
2019-03-04 06:50:05 +01:00
public OctetString()
:base(new Identifier(IdentifierClass.UNIVERSAL, false, 4))
{
2019-03-11 08:57:19 +01:00
StringValue = "";
2019-03-04 06:50:05 +01:00
}
public OctetString(String text)
2019-03-11 08:57:19 +01:00
: this()
2019-03-04 06:50:05 +01:00
{
StringValue = text;
}
2019-03-11 08:57:19 +01:00
public OctetString(byte[] bytes)
: this()
{
Bytes = bytes;
}
2019-03-04 12:06:45 +01:00
public override string ToString()
{
2019-03-11 08:57:19 +01:00
return String.Format("[OctetString StringValue={0}]", StringValue.Replace("\0","\\0"));
2019-03-04 12:06:45 +01:00
}
public static implicit operator String(OctetString octetString)
{
return octetString.StringValue;
}
public static implicit operator OctetString(String text)
{
return new OctetString(text);
}
2019-03-04 06:50:05 +01:00
}
}