feat(sdk): add ScalarRecord/ObjectRecord for parser-controlled timestamps#92
Merged
Merged
Conversation
…amps
Introduce ScalarRecord {optional<Timestamp> ts, vector<NamedFieldValue>}
and ObjectRecord {optional<Timestamp> ts, BuiltinObject} as the new
return types of the SchemaHandler parse_scalars / parse_object
callables.
When ts is nullopt the host uses the message receive time as before;
when set, the parser-provided timestamp is used instead — restoring
the ability to align rows with timestamps embedded in the payload
(e.g. ROS Header.stamp, JSON "timestamp" field, sensor capture time).
The default parse() now iterates the returned records and respects each
record's timestamp, also enabling multi-row output from a single payload
(useful for batch messages such as JSON arrays).
…oc per call Review feedback: returning std::vector<ScalarRecord> meant every call ended up doing two heap allocations in the common case (outer vector + the fields vector inside the only record), even for single-row decoding on a hot streaming path. The parser-controlled timestamp was the actual ask from the client; multi-row batch was added speculatively for JSON arrays and is not a shipping requirement. Drop the outer vector and return a single ScalarRecord; one allocation total, same shape as the pre-change API plus the optional<Timestamp>. Parsers that need to emit multiple rows per payload can stage a batch API later if/when a concrete use case shows up — the SchemaHandler shape leaves room for that without breaking ScalarRecord.
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 `ScalarRecord { optional ts, vector fields }` and `ObjectRecord { optional ts, BuiltinObject object }` as the new return types of the `SchemaHandler` `parse_scalars` / `parse_object` callables.
When `ts` is `nullopt` the host uses the message receive time as before; when set, the parser-provided timestamp is used instead — restoring the ability to align rows with timestamps embedded in the payload (e.g. ROS `Header.stamp`, JSON `"timestamp"` field, sensor capture time).
`parse_scalars` returns a single `ScalarRecord` (one allocation, same shape as the previous `vector` plus the optional timestamp). Multi-row batch from a single payload is intentionally out of scope to keep the hot path one-allocation; if a real batch use case appears it can grow into a dedicated API without changing the `ScalarRecord` shape.
API change
Signatures change in `SchemaHandler`:
Parsers that don't care about embedded timestamps can leave `ts = std::nullopt` and keep their previous behaviour. Parsers that do can now place the value where the host actually reads it.
Test plan