Skip to content

feat: attr_get / attrs_get attribute accessors (1.4.0)#6

Merged
andrewstarks merged 1 commit into
mainfrom
feat/attr-accessors
Jun 1, 2026
Merged

feat: attr_get / attrs_get attribute accessors (1.4.0)#6
andrewstarks merged 1 commit into
mainfrom
feat/attr-accessors

Conversation

@andrewstarks
Copy link
Copy Markdown
Owner

Summary

Adds two module-level accessors that look up decomposed attributes by name on a block (a `doc.session` or any `doc.media[i]`):

  • `sdp.attr_get(block, name)` — first matching attribute table, or `nil`
  • `sdp.attrs_get(block, name)` — array of all matches in document order (empty table when none)

Both are nil-safe and mirror `parse_sdp.grammar.base.params_get` (the inner-`fmtp` accessor) for the outer `attributes` array, so consumers no longer hand-roll the scan over the ordered array. `attrs_get` earns its place because same-name attributes are common (`rtpmap` / `fmtp` / `ssrc` / `rtcp-fb`).

Requested by the `lnmos` projection layer, which was the only consumer still hand-rolling `find_attr`.

Design

  • Defined once in `grammar/base.lua` beside `params_get`, inherited through `extend()`, re-exported on the public module in `init.lua`.
  • Free functions, not block methods — works identically on parsed and `sdp.new()` docs with no metatable surface on blocks, and no impact on `to_json()` / round-trip.

Tests

+9 cases in `spec/library_spec.lua` (first / all / session-level / flag-only / miss / nil-safe / hand-built). Full hermetic suite green.

Release

Bumps rockspec to 1.4.0 (additive, backward-compatible). dkjson dependency unchanged.

🤖 Generated with Claude Code

Add module-level sdp.attr_get(block, name) and sdp.attrs_get(block, name)
to look up decomposed attributes by name on a session or media block,
mirroring grammar.base.params_get for the outer attributes array. attr_get
returns the first match (or nil); attrs_get returns all matches in order.
Removes the hand-rolled scan from every consumer. Bumps rockspec to 1.4.0.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@andrewstarks andrewstarks merged commit 5d72966 into main Jun 1, 2026
6 checks passed
@andrewstarks andrewstarks deleted the feat/attr-accessors branch June 1, 2026 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant