c# - How can I generalize the use of these different data structures? -
I have an application that reads a file from a bar
[StructLayout ( LayoutKind.Sequential, Pack = 1] Public Structure IntraPacketTime_RTC {Public UInt64 RTC: These times as shown below, there may be three different formats depending on flag bits in the file;} [StructLayout (LayoutKind.Sequential , Pack = 1] Public Structure IntraPacketTime_Ch4 {Public Unused UInt16; Public UInt16 TimeHigh; Public UInt16 TimeLow; Public UInt16 Micros You can see all three time formats: source data file; StructLayout (LayoutKind.Sequential, Pack = 1] public struct IntraPacketTime_IEEE1588 {public UInt32 nanosecond; public UInt32 seconds;}
It takes up to eight bytes, but these eight bytes are differently , depending on the set time format
However, production time is always the same format, the way This (the source data is stored in the file, either YYY hH Without :. MM: DD SS SSSSS , where ssssss are a fraction of each other, or SSSSS.ss ssss seconds and partial seconds past midnight) .
I read these data from the data file and use them in a normal way, without case
statement all the place? Is there a software pattern that makes it easy to make, is it more generalized, and the abstract is to create some of the distant complexity? Text structure after layout (LayoutCind.exe)] Public structure Intra packet time {{Field offset}
(0)] Private UIIT 64 RTC; [Field Offset (0)] Private UiIT 32 Nanosconds; [Field Offset (4)] Private UInt32 Seconds; [Field Offset (0)] Private UInt16 Unused; [Field Offset (2)] Private UInt16 Timehau; [Field Offset (4)] Private UIIT 16 Timeline; [Field Offset (6)] Private UInt16 microsecond; Public Datetime GetTime (Intra Packet Timeform Format) {Switch (Format) {...}} Public Clear Operator Intra Packetime (Int 64 Value) {New intra packet time {RTC = value; }}} Public enum IntraPacketTimeFormat {None, RTC, Ch4, IEEE1588,}
You should be able to use
IntraPacketTime t = (IntraPacketTime ) BinaryReader .ReadInt64 (); Var time = t. GateTime (4 of Intra Packet Timeform.);
Comments
Post a Comment