feat(core): typed batch references grouped by protocol category - #15
Merged
Conversation
Batch requests are reached through the protocol's own categories, so b.Scenes.GetSceneList rather than one flat list of 147 methods, and each returns a BatchRef carrying its response type. Results are read with results.Get(reference), which restates neither the position nor the type and stays correct when a request type appears several times in one batch. Replaces the chainable positional methods; capturing a reference needs a statement per request anyway. Count stays at one method per request. LOGGEN036 is fixed by typing the generated log parameters rather than suppressing the diagnostic.
Reading them from the shared reader let one result's payload slice run on into the next. Both transports now slice each result out first. Parallel batches still mis-pair responseData and are tracked in #16; serial batches, single requests and both transports are verified by value.
- Add overloads return a BatchRef; the raw index accessor is internal so an index cannot be paired with the wrong response type - BatchResults is an IReadOnlyList - OverloadResolutionPriority settles Add(null) between the two overloads - net11 uses the typed GetTypeInfo<T> overload - The example covers stream buffering under capacity pressure
OBS collects parallel batch results in completion order but labels them from the submission order, so responseData and requestStatus belong to a different request than requestType and requestId say. Confirmed in obs-websocket: RequestBatchHandler.cpp appends results as tasks finish, and WebSocketServer_Protocol.cpp zips that vector against the original request array by index. Reading one by reference now refuses and explains, rather than returning another request's data. Raw stays available. Tracked in #16.
mediaDuration, mediaCursor and transitionDuration are only null in a particular state, which the protocol states in the field description rather than in valueOptional, so they were generated as non-nullable and failed to deserialize whenever OBS actually sent null. MessagePack threw outright; JSON reported a missing payload. The example now reads state back after a media action and cross-checks the output helpers against the requests they wrap, which is what surfaced it.
26 tasks
Requests and conveniences now sit together in the category they belong to, so client.Scenes.GetSceneListAsync and client.Scenes.SwitchProgramSceneAsync read the same way and IntelliSense offers 14 categories rather than 147 flat methods. The groups are partial structs, so generated and hand-written members share one type and same-named overloads resolve naturally. The flat extension methods are gone; the batch builder already used these categories, so both halves of the library now address OBS identically. SceneItemNotFoundException moves out of the static helper class it was nested in.
AddObsWebSocketClient(name) reads the endpoint from ConnectionStrings, so OBS is configured like any other resource an application connects to, with the password kept off ServerUri. WithAutoConnect replaces the background service every consumer was writing, and treats an unreachable OBS at startup as survivable rather than fatal since it is usually started later. AddObsWebSocket registers a health check for the connection.
Options resolve through IOptionsMonitor rather than the values captured when the container was built, so a timeout or reconnect setting applies to the next call that reads it. Changing the endpoint, password or transport cycles the connection, which the auto-connect service performs.
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.
Acts on the batch DX review, plus the LOGGEN036 warnings that appeared once
Microsoft.Extensions.Resiliencepulled in the stricter logging generator.Typed references
Each batch request now hands back a reference carrying its response type, and requests are reached through the protocol's own categories:
Neither the position nor the response type is restated at the call site, and a request type can appear many times in one batch with each reference still resolving to its own result.
The categories are OBS's own
categoryfield fromprotocol.json, not invented here, so they track the protocol on refresh: canvases, config, filters, general, inputs, media inputs, outputs, record, scene items, scenes, sources, stream, transitions, ui.This replaces the chainable positional methods rather than adding to them. Capturing a reference takes a statement per request anyway, so the generated method count stays at 147 rather than doubling.
Also
TryGetreports a failed or missing result without throwing; reading a reference past ahaltOnFailuretruncation throws with a message saying why.Addgains aJsonTypeInfo<T>overload so custom payloads stay AOT-safe.Verified
run-transport-testspasses on JSON and MessagePack against OBS 32.2.2, including a batch that repeats one request type three times with two different payloads and reads each back through its own reference.