Add struct-based SimVar set functionality#11
Merged
AussieScorcher merged 1 commit intostopbars:mainfrom Oct 20, 2025
Merged
Conversation
Introduces IFieldWriter, SimVarFieldWriter, and SimVarFieldWriterFactory to enable writing SimVar-annotated structs into unmanaged buffers. Adds SimVarManager.SetAsync<T> and SetStructAsync for setting multiple SimVars in one call using a struct. Updates tests to verify struct-based SimVar setting and restoration.
Contributor
There was a problem hiding this comment.
Pull Request Overview
Adds a struct-based API to set multiple SimVars in a single call, mirroring the existing struct-based GetAsync path.
- Introduces SimVarManager.SetAsync(T value, ...) to write annotated struct fields in one request
- Implements internal writer pipeline (IFieldWriter, SimVarFieldWriter, SimVarFieldWriterFactory) to pack struct data into the unmanaged buffer using the same field layout as the get path
- Adds a test validating altitude change via struct set and restore
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/SimConnect.NET/SimVar/SimVarManager.cs | Adds public SetAsync and internal SetStructAsync to build and send packed struct data to SimConnect. |
| src/SimConnect.NET/SimVar/Internal/SimVarFieldWriterFactory.cs | New factory to reflect annotated struct fields, infer types, and build writers and layout sizes. |
| src/SimConnect.NET/SimVar/Internal/SimVarFieldWriter.cs | Writer that marshals each field into the unmanaged buffer based on SimConnectDataType. |
| src/SimConnect.NET/SimVar/Internal/IFieldWriter.cs | Interface for writing a single field into a packed buffer. |
| tests/SimConnect.NET.Tests.Net8/Tests/SimVarTests.cs | Adds a test to validate struct-based SetAsync for Position (altitude + restore). |
AussieScorcher
approved these changes
Oct 20, 2025
Member
|
Amazing work! Will merge and be pushing a new SimConenct.NET version shortly :) |
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.
Summary
Introduce a new API to set multiple SimVars in one call using a strongly-typed struct:
SimVarManager.SetAsync<T>(T values, CancellationToken ct = default)Usage Example
Where
Positionis:Tests
SetAsync<T>.Performance & Reliability
Author Information
Discord Username: bstudtma
Checklist: