Replies: 2 comments
-
In general, the System.Formats.Asn1 library is only providing things from X.680/X.690. Reading a BACnetTimeStamp is outside the scope of what it should perform. One could make a BACNet library that is powered by, and builds on, System.Formats.Asn1.. but the only things that should obviously be built-in (that is, built into System.Formats.Asn1) are those things defined in the core ITU specifications The library can even provide extension methods, as appropriate: public static BACNetTimeStamp ReadBACNetTimeStamp(this AsnReader reader)
{
ArgumentNullException.ThrowIfNull(reader);
AsnReader temp = new AsnReader(reader.PeekEncodedValue(), reader.RuleSet);
AsnTag tag = reader.PeekTag();
if (tag.TagClass != TagClass.ContextSpecific)
{
throw new SomeException();
}
AsnReader inner = temp.ReadSequence(tag);
BACNetTimeStamp timeStamp = tag.TagValue switch
{
0 => ReadTime(inner),
1 => ReadUnsigned(inner),
2 => ReadBACNetDateTime(inner),
_ => throw new SomeException(),
};
inner.ThrowIfNotEmpty();
// Everything worked, update the reader's state.
reader.ReadEncodedValue();
return timeStamp;
} |
Beta Was this translation helpful? Give feedback.
-
Thanks @bartonjs for response. It's a shame it doesn't cover this but understand it can't support everything. |
Beta Was this translation helpful? Give feedback.
-
I believe I asked (or searched around) before but couldn't find the answer on how it would be possible to extend System.Formats.Asn1 to use other rules. Meaning, use the API to read/wirte/encode/deocde bytes to and from objects other than the provided 3 types. The BACnet protocol (basic example below) defines the various objects/services and would be great to use this API (or at least utilize most of the provided). It does appear like there are a few items missing like Date, as well.
CCing @bartonjs or @stephentoub to see if they had some options. Thx
An example of a context-tagged Boolean is below where it would produce a byte array of 0x2901.
Beta Was this translation helpful? Give feedback.
All reactions