6.0 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |||
|---|---|---|---|---|---|---|---|
|
2026-04-16T03:43:04.052592+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 32d5e734af040685 |
IRIG CH10 Attribute Decoders Documentation
1. Purpose
This module provides utility classes for extracting metadata annotations from .NET enum values, specifically tailored for IRIG CH10 data format compliance. It enables serialization logic to retrieve human-readable descriptions, maximum length constraints, packet header values, and data type version numbers associated with enum fields via custom attributes (DescriptionAttribute, MaxLengthAttribute, PacketHeaderValueAttribute, DataTypeVersionValueAttribute). These utilities bridge the gap between strongly-typed enum definitions and the string/byte-level requirements of the IRIG CH10 specification (e.g., TMATS file generation, packet header construction).
2. Public Interface
DescriptionDecoder.GetDescription(Enum value)
- Signature:
public static string GetDescription(Enum value) - Behavior: Returns the
DescriptionAttribute.Descriptionvalue attached to the enum field corresponding tovalue. If no such attribute exists, returns the enum'sToString()representation.
MaxLengthDecoder.GetMaxLength(Enum value)
- Signature:
public static int GetMaxLength(Enum value) - Behavior: Returns the
Lengthproperty of theMaxLengthAttributeattached to the enum field corresponding tovalue. If no such attribute exists, returns0.
PacketHeaderValueAttribute.GetPacketHeaderValue(Enum value)
- Signature:
public static byte GetPacketHeaderValue(Enum value) - Behavior: Returns the
PacketHeaderValueproperty of thePacketHeaderValueAttributeattached to the enum field corresponding tovalue. If no such attribute exists, returnsDefault.PacketHeaderValue(which is0x00).
DataTypeVersionValueAttribute.GetDataTypeVersionValue(Enum value)
- Signature:
public static byte GetDataTypeVersionValue(Enum value) - Behavior: Returns the
DataTypeVersionValueproperty of theDataTypeVersionValueAttributeattached to the enum field corresponding tovalue. If no such attribute exists, returnsDefault.DataTypeVersionValue(which is0x00).
Note
: The static methods
GetPacketHeaderValueandGetDataTypeVersionValueare instance methods on their respective attribute classes, not static methods on the class itself. They are called on the attribute class (e.g.,PacketHeaderValueAttribute.GetPacketHeaderValue(someEnum)) and operate on the enum value passed.
3. Invariants
- Enum Field Resolution: All decoder methods assume the
Enumvalue corresponds to a valid field name in its declaring type (viavalue.ToString()→GetField()). If the enum value is invalid or the field name resolution fails (e.g., due to compiler-generated names or customToString()overrides), behavior is undefined (likely throwsNullReferenceExceptionor returns incorrect data). - Attribute Uniqueness: Methods return the first attribute found via
GetCustomAttributes(...). If multiple attributes of the same type exist on a single field, only the first is used. - Default Values: When no attribute is present:
GetDescriptionfalls back tovalue.ToString()GetMaxLengthreturns0GetPacketHeaderValuereturns0x00GetDataTypeVersionValuereturns0x00
- Attribute Scope:
PacketHeaderValueAttributeandDataTypeVersionValueAttributeare decorated with[AttributeUsage(AttributeTargets.All)], meaning they can be applied to any program element (not just enums), though the decoders assume usage on enum fields.
4. Dependencies
Dependencies of this module:
- System.ComponentModel: For
DescriptionAttribute - System.ComponentModel.DataAnnotations: For
MaxLengthAttribute - System.Linq: For
Any()andFirst()LINQ methods - System.Reflection: For
GetType(),GetField(),GetCustomAttributes()
Dependencies on this module:
- Other IRIG CH10 serialization components (not visible in source) that rely on these decoders to:
- Generate TMATS string descriptions from enums
- Enforce or suggest max-length constraints for string fields
- Construct packet headers (e.g., for packet type/version identification)
- Serialize data type version information per CH10 spec
5. Gotchas
- No null-safety: All methods call
value.ToString()andGetField(...)without validating thatvalueis non-null or that the field exists. Passingnullor an invalid enum value will cause aNullReferenceException. - Case sensitivity:
value.ToString()is used directly forGetField(). If the enum field name differs in casing (e.g., due to compiler optimizations or customToString()overrides), field resolution may fail. MaxLengthAttributeis advisory only: As noted in theMaxLengthDecodersummary, CH10 specifies max lengths as suggestions, not hard requirements. Consumers should not assume enforcement.- Default attribute behavior: The
Defaultstatic fields (PacketHeaderValueAttribute.Default,DataTypeVersionValueAttribute.Default) are new instances with0x00values—not singleton references to a shared default. This is safe but worth noting for equality comparisons. - No validation of attribute targets: While
PacketHeaderValueAttributeandDataTypeVersionValueAttributeallowAttributeTargets.All, their staticGet*Valuemethods assume usage on enum fields. Applying them to non-enum members (e.g., classes, methods) will likely cause runtime errors. - No support for inherited attributes:
GetCustomAttributes(..., false)excludes inherited attributes. If attributes are defined on base enum values (in inheritance hierarchies), they will be ignored.
None identified from source alone beyond those above.