Skip to content

feat(kernel): publish and receive objects of runtime classes - #536

Draft
EnriqueParodi wants to merge 10 commits into
mainfrom
feat/runtime-classes
Draft

EnriqueParodi wants to merge 10 commits into
mainfrom
feat/runtime-classes

Conversation

@EnriqueParodi

@EnriqueParodi EnriqueParodi commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

What and why

Sen fully supports only objects whose class has generated C++ code. A gateway that reads an from a different protocol at runtime has no generated code for the classes it finds, so it cannot publish objects of them, and a subscriber that knows a class only at runtime has its remote objects refused at discovery. This change closes the gap with Sen's existing mechanisms, without a new kernel registry.

  • Receiving. GenericRemoteObject, the proxy for a remote object whose class has no generated proxy here, is now an installed detail header. A remote object of a class known only at runtime reaches its subscribers instead of throwing at discovery. When the writer's class differs from the reader's, members are decoded with the writer's types and converted, matched by name, as generated proxies do.
  • Publishing. GenericLocalObject holds each property as its Sen encoding and otherwise behaves like a generated object: values take effect at the next commit, and it writes the same updates a generated object of the same class writes. Queries filter on it through EncodedFieldReader, a new core class that reads one field straight from a property's encoding.
  • Local proxies. NativeObject::senImplMakeLocalProxy lets an object provide the proxy that subscribers in the same process hold. By default it returns the class's generated proxy, as before. GenericLocalObject provides a GenericLocalObjectProxy.
  • Compatibility check. A remote alias is now checked as the type it aliases, so a FOM's Octet matches a generated u8 instead of being refused.
  • Replayer. Replayed objects use the generic local proxy instead of a proxy maker installed on the recorded class for the whole process. State writes on a replayed object's local proxy, which threw, now work, and a live object of a replayed class no longer crashes its local subscribers.

For users: NativeObject gains a virtual function, so components must be rebuilt. A subscriber in the same process as a replay reads replayed values as of its last update, like any generated proxy, instead of live.

Tests: unit tests for each new class, including a comparison of GenericLocalObject with a generated object of the same class (36 query paths, and every write mode byte for byte). Two integration tests run across processes: a subscriber that imports the FOM at runtime receives objects from generated code, and a runtime publisher reaches a generated subscriber. Replayer tests cover the operations that threw. The replayer benchmark is as fast as before or faster with subscribers in the same process.

Checklist

  • The title follows type(scope): summary and stays under 72 characters
  • This pull request is a single logical change
  • Tests cover the change where practical
  • .conan/conan.lock was regenerated if conanfile.py changed (it did not change)

The runtime compatibility check refused a remote alias against the type
it aliases. A generated subscriber holding a u8 refused a publisher
whose class holds a FOM's Octet, an alias of u8, and the publication was
rejected.

Where the check compares what the remote side writes with a local type
that is neither an alias nor an optional, a remote alias is now taken as
the type it aliases. Only refusals can become acceptances: a class
accepted before is accepted the same, with the same lossy conversions.
A local alias or optional is checked as before, and so are method
arguments, where the two sides are swapped.

getRuntimeDifferences, used for a debug log, also lists a remote alias
as the type it aliases, unless the local type is an alias.

Release note: a remote class whose members are aliases of the local
class's member types is now accepted instead of refused.
GenericRemoteObject's header moves from the kernel's private sources to
sen/kernel/detail/ and is installed with the kernel's other detail
headers, so that code outside the kernel can tell a GenericRemoteObject
from a generated proxy. Only the include guard changes, and the two
includes of the old path are updated.

Release note: new installed detail header
sen/kernel/detail/generic_remote_object.h.
When the writer's class differed from the reader's, GenericRemoteObject
decoded a changed property or event argument with the reader's type,
from bytes in the writer's layout. The value was misread, and so was the
rest of the stream.

A changed member is now decoded with the writer's type and converted to
the reader's, as generated proxies do in RemoteObject::readOrAdapt.
Members are matched by name, never by position, so a renamed field or
argument counts as a different member. An event with an argument that
has no match among the writer's is dropped with a warning. Members whose
types agree, and identical classes, are read as before.

The class is exported and documented now that its header is installed.
Unit tests cover a widened property, an unchanged class, a reordered and
widened event argument, and an event dropped for a missing argument.
A remote object whose class the local kernel knows but has no proxy
makers for, such as a class built at runtime, was refused at discovery
with a logic_error, and its subscribers never received it. It now gets a
GenericRemoteObject of the local class, which startTrackingProxy already
creates for a class without makers. Classes with makers are unaffected.

Release note: a subscriber whose kernel knows a class only as a runtime
definition now receives remote objects of that class as
GenericRemoteObjects, instead of an exception at discovery.
sen::impl::EncodedFieldReader reads one field of a property directly
from the property's Sen encoding. It lets query filters work on objects
that hold their properties encoded and have no generated code, such as
GenericLocalObject.

resolve() works out once where the field sits in the encoding; read()
then takes it from the current bytes without decoding the rest. It
returns what a generated getter returns, so a filter gives the same
answer on both kinds of object. The exception is an optional, which it
reads as its value or as no value, where a generated getter cannot read
one.

Release note: new installed core detail header
sen/core/obj/detail/encoded_field_reader.h.
NativeObject gains senImplMakeLocalProxy, which returns the proxy a
subscriber in the same process holds for the object, already holding
the object's current state. The default is what the proxy manager did:
the class's generated local proxy, drained once; a null proxy is no
longer drained. The proxy manager now calls it, so an object whose
values a generated proxy cannot read can provide its own proxy. The
choice is made per object, not per class.

Release note: NativeObject has a new virtual function,
senImplMakeLocalProxy, so components must be rebuilt.
GenericLocalObject is a NativeObject for a class with no generated code,
such as one read from a FOM at runtime. It holds each property as its
Sen encoding, so a gateway can publish what it decodes without building
Vars. Values are set by index, or as a block of records keyed by
property id, and become current at the next commit, as in a generated
class. It writes the same updates a generated object of the same class
writes. A class with generated proxy makers is rejected, and so is an
empty value. Queries read it through EncodedFieldReader. Only property
getters can be called on it.

GenericLocalObjectProxy is the local proxy GenericLocalObject makes
through senImplMakeLocalProxy. Like a generated proxy, it keeps its own
copy of the values, updated at each drainInputs, and notifies the
properties that changed. It reads the object through
EncodedPropertyValues, comparing each encoding with its copy and copying
only what differs. Given PropertyChangeTimes, it notifies a property
whenever its change time moves, stamped with that time. Generated
proxies and GenericRemoteObject are unaffected.

Release note: new installed detail headers
sen/kernel/detail/generic_local_object.h and
sen/kernel/detail/generic_local_object_proxy.h.
One process publishes dummy_entities' generated aircraft. The other
imports the FOM that dummy_fom is generated from at runtime, into its
own registry, and subscribes with an interest built from that registry.
The test passes when the aircraft arrives as a GenericRemoteObject of
the imported class, with its entity type read as sent. It depends on the
discovery fix and on reading in the writer's layout.

runner.py now accepts any number of supporting instances before the
tester, so a two-process test needs no third. Existing three-argument
runs are unchanged.
One process imports the FOM at runtime into its own registry and
publishes an aircraft as a GenericLocalObject. The other uses
dummy_fom's generated classes and subscribes through the typed
interface. The test passes when three changes arrive through the
generated proxy as they were set, with the entity type intact. It
depends on the alias fix in the compatibility check: the FOM's simple
data types are aliases at runtime and native types in generated code.
The replayer installed its own local proxy maker on each recorded class,
process-wide, and never removed it. A subscriber in the same process got
a ReplayedObjectProxy, whose state writes and typed connection removal
threw std::logic_error, so a recorder in the same process could not
snapshot a replay. When the recorded class had generated code, the maker
also served live objects of that class, and their local subscribers
crashed on a null owner.

ReplayedObject now implements EncodedPropertyValues and
PropertyChangeTimes, and makes a GenericLocalObjectProxy as its local
proxy. The maker injection and ReplayedObjectProxy are removed.
Subscribers get the same notifications as before: each property whose
recorded time moved, stamped with that time, statics and repeated values
included. Reads come from the subscriber's copy as of its last update,
as with generated proxies, so a value read always matches the last
change notified; ReplayedObjectProxy read the replayed object live. The
state writes give that copy, and removing a typed connection does
nothing.

Tests cover a subscriber in another component recording a replay, a live
object of a replayed class keeping its generated proxy, the notified
times, and a value changed without its time moving, which is read but
not notified.

Release note: a subscriber in the same process as a replay can snapshot
and record replayed objects, and live objects of a replayed class keep
their generated local proxies. Replayed objects are read as of the
subscriber's last update.
@EnriqueParodi EnriqueParodi self-assigned this Oct 30, 2026

This branch has not been deployed

No deployments
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