Attribute-driven data fields, extra data support and span-based parsing - #130
Merged
Merged
Conversation
…8 and 9 to sub/unsub mid to be an int (UI in documentation)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every MID in the library was rewritten to describe its data fields through attributes on the properties themselves, instead of building a
Dictionary<int, List<DataField>>by hand and lazily converting values on every property access. Parsing now walks the package as aReadOnlySpan<char>and writes the converted value straight into the property, and packing reads it back from there.Breaking changes
Property type changes
Mid0008SubscriptionMidstringintMid0009UnsubscriptionMidstringintMid0105,Mid0106,Mid0107DataNumberSystemintlongMid1201ResultDataIdentifierintlongMid1201ResultStatusboolintMID 0008/0009 now expose the subscribed/unsubscribed MID as an
int, matching the documentation (and matchingMid0006.RequestedMid, which was already anint).Removed / changed members
Mid0702.ToolNumberwas removed — MID 0702 is answered from a MID 0006 request whose extra data carries the tool number, so it now lives inMid0702ExtraData.Mid0702.NumberOfToolParameters(read-only) became the settableNumberOfToolPIDs.DataField.String/Boolean/Timestamp/...factory methods now returnDataField<T>instead ofDataField. Source compatible when the result is assigned to aDataField, binary breaking.VariableDataField.ParseAllandOpenProtocolConvert.ToString(...)for variable data fields now work withList<VariableDataField>instead ofIEnumerable<VariableDataField>.Custom MIDs inheriting from
MidThe parse/pack pipeline is span based, so MIDs that override it need their signatures adjusted:
ProcessDataFields(string)→ProcessDataFields(ReadOnlySpan<char>)(plus the new per-field hookProcessDataField(DataField, ReadOnlySpan<char>), which is usually what you want to override now)Pack(int revision, ref int prefixIndex)→Pack(int revision)Pack(List<DataField>, ref int prefixIndex)→Pack(IEnumerable<DataField>)GetValue(DataField, string)→GetValue(DataField, ReadOnlySpan<char>)RegisterDatafields()is stillvirtualand still works exactly as before, so a custom MID written against the old style keeps working as long as it doesn't override the methods above.Packaging
netstandard2.0target now depends onSystem.Memory(4.5.5) forSpan<T>.Improvements
Header,Mid,DataField,OpenProtocolConvert), slicing the package instead of allocating substrings.netstandard2.0keeps the oldstringpath behind#if.Header.Parse(string)/Header.Parse(ReadOnlySpan<char>)are now public, so you can read the MID number, revision and length without going throughMidInterpreter(Suggestion: Expose functionality to parse String to Header #118).OpenProtocolConvertoverloads forDateTimeOffset/unix timestamps and span inputs.New Features
DefaultEncodingproperty atMidand an overload atbyte[]methods (Encoding is in reality UTF-8 for PF 6000 #117)Mid0006,Mid0008andMid0009Extra data based on pre build extra data, also, enabled to create your own withIExtraDataRequest,IExtraDataSubscriptionandIExtraDataUnsubscriptioninterfaces. (Generate extra data atMid0008by providing the desired mid to subscribe #104)Mid.GetField(string propertyName)andGetField<T>(int revision, int field)for the cases where a field's size only becomes known after another field has been read.Bug fixes
Int32DataFieldDefinition— the underlying value wasn't being converted to the enum type.netstandard2.0, which has noDateTimeOffset.UnixEpoch.Mid0001,Mid0002,Mid0004,Mid0005,Mid0006,Mid0008,Mid0009,Mid0061,Mid0200,Mid0214,Mid0215,Mid0251,Mid0254,Mid0255,Mid0265,Mid0401,Mid0411.Mids updates
Mid2502(password request)Mid2503(password response).Mid0001/Mid0002(OptionalKeepAlive,OptionalToolLockAtDisconnection,OptionalEarlyLock,StationCellId)Mid0045(ExtendedCalibrationValue,TransducerNumber)Mid0065ToolTypevalues (XPBM,ExBC,ExD).Mid0015Mid0035Mid0061Mid0065(JointId,SelectedIdentifierNumber,NumberOfStagesInMultistage,NumberOfStageResults).PIDRestrictiontype added forMid0704.Funding
Added
.github/FUNDING.ymlwith GitHub Sponsors and Buy Me a Coffee (rickedbon both), so the repository shows the "Sponsor" button. This project has been maintained on free time for years — if it saves you or your company some of it, that button is now there. It changes nothing about the license or the roadmap: the library stays MIT and issues/PRs are handled the same way.Related issues
Mid0008by providing the desired mid to subscribe #104