Skip to content

SDK API Reference

Passed to ConvergenceClient.ConnectAsync().

PropertyTypeDefaultDescription
HoststringrequiredServer hostname or IP address.
PortintrequiredServer TCP port (default ConvergeDB port: 3727).
SourceIdbyterequiredWriter identity (0-63). Each independent process should use a distinct value.
Namestring?nullHuman-readable name for this client. Visible to other clients via the convergedb_connections system kind. See Client Presence.
AuthTokenstring?nullAuthentication token sent in the CONNECT frame.
LivenessDeadlineMsuint30000How long the server preserves this client’s entities after disconnect before retracting them. Must be greater than HeartbeatIntervalMs.
HeartbeatIntervalMsint15000How often the client sends a heartbeat to keep the connection alive.
ReconnectMaxDelayMsint10000Maximum reconnection back-off delay.
SubscriberBufferSizeint4096Bounded capacity of each subscription’s internal notification channel.
PropertyTypeDescription
ConnectionsKindHandle<ConvergeDbConnection>Pre-resolved handle for the built-in convergedb_connections system kind. Subscribe to observe connected clients. See Client Presence.
MethodReturnsDescription
ConnectAsync(options)ConvergenceClientConnect to a ConvergeDB server.
RegisterKindAsync<T>()KindHandle<T>Register an entity kind (writers), returns a typed handle. Storage mode (in-memory or disk-backed) is determined by the [ConvergenceEntity] attribute.
ResolveKindAsync<T>()KindHandle<T>Resolve a kind without mutation (readers). Validates the client’s schema is a compatible prefix of the server’s.
CreateKindAsync(name, fields)ushortLow-level: create entity kind, returns KindId.
GetKindAsync(name, fields)GetKindResultLow-level: read-only schema resolution, returns KindId + schema version + field count.
AssertAsync(kindId, entityId, fieldData)TaskLow-level: buffer an Assert (requires FlushAsync).
PatchAsync(kindId, entityId, fieldData, mask)TaskLow-level: buffer a Patch (requires FlushAsync).
RetractAsync(kindId, entityId)TaskLow-level: buffer a Retract (requires FlushAsync).
FlushAsync()TaskFlush all buffered writes to the TCP socket.
Batch()ConvergenceBatchCreate a cross-kind batch that flushes on dispose.
QueryAsync(kindId, entityId)EntityQueryResultLow-level: point read.
SubscribeAsync(kindId, bootstrap, includePrevious, reconnectMode)SubscriptionHandleLow-level: subscribe to a kind.
EpochBeginAsync()TaskBegin a source epoch.
EpochEndAsync()TaskEnd a source epoch, retracting stale entities.
EpochAsync(Func<Task>)TaskConvenience: Begin + callback + End.

Returned by client.GetKindAsync().

PropertyTypeDescription
KindIdushortThe server’s kind ID.
SchemaVersionbyteThe server’s current schema version.
FieldCountushortTotal field count on the server (may exceed the client’s known fields).

Obtained via client.RegisterKindAsync<T>() (writers) or client.ResolveKindAsync<T>() (readers). Thread-safe singleton.

MethodReturnsDescription
AssertAsync(entity)TaskAssert a typed entity (auto-flush).
AssertAsync(entity, metadata)TaskAssert with metadata.
PatchAsync(patch)TaskPatch a typed entity (auto-flush).
PatchAsync(patch, metadata)TaskPatch with metadata.
RetractAsync(entityId)TaskRetract a typed entity (auto-flush).
RetractAsync(entityId, metadata)TaskRetract with metadata.
QueryAsync(entityId)T?Typed point read. Returns null if not found.
SubscribeAsync(bootstrap, includePrevious, reconnectMode, ct)IAsyncEnumerable<EntityChange<T>>Typed subscription.
Batch()KindBatch<T>Single-kind batch that flushes on dispose.
BootstrapSnapshotAsync(ct)IReadOnlyList<T>One-shot bootstrap: subscribe, collect, unsubscribe.
SubscribeEventsAsync(ct)IAsyncEnumerable<EntityEvent<T>>Subscribe to per-assert events. The kind must have been registered with EventStream = true. Returns individual operation events (not coalesced state). No bootstrap is available since events are ephemeral. See Event Streams for details.

Yielded by KindHandle<T>.SubscribeAsync().

PropertyTypeDescription
TypeNotificationTypeCreated, Updated, Deleted, or Bootstrap.
EntityT?Current entity state. Null for Deleted.
PreviousEntityT?Previous state (only for Updated with includePrevious).
EntityIdReadOnlyMemory<byte>The 32-byte entity ID.
VersionulongMonotonically increasing per entity.
SourceSetulongBitmask of asserting sources.
ChangedFieldsulongBitmask of fields that changed.
MetadataReadOnlyMemory<byte>Opaque metadata from the write operation.
MethodReturnsDescription
HasChanged(int fieldIndex)boolCheck if a specific field changed.

Yielded by KindHandle<T>.SubscribeEventsAsync().

PropertyTypeDescription
TypeEventTypeCreated, Updated, or Retracted.
VersionulongCommitted entity version from the flush cycle.
PrevVersionulongCommitted entity version before this flush cycle. 0 for Created.
SourceIdbyteWhich source (0-63) produced this operation.
SequenceulongPartition-global monotonic sequence number.
EntityT?Deserialized assert payload (null for Retracted). This is the raw assert data, not the converged state.
PreviousEntityT?Previous entity state that ChangedFields was computed against (null for Created/Retracted). Forms a diff triple with Entity and ChangedFields.
ChangedFieldsulongBitmask of fields changed by this assert. MaxValue for Created, 0 for Retracted.
PresenceMaskulongFor PATCH: which fields were present.
MetadataReadOnlyMemory<byte>?Opaque metadata from the assert/retract.
MethodReturnsDescription
HasChanged(int fieldIndex)boolCheck if a specific field was changed by this assert.

Returned by the low-level client.SubscribeAsync().

Property / MethodTypeDescription
KindIdushortThe subscribed kind.
BootstrapStatusBootstrapStateCurrent bootstrap state.
BootstrapEntityCountHintuintApproximate entity count from BOOTSTRAP_BEGIN.
BootstrapStatusChangedevent Action<BootstrapState>Fires on each state transition.
ReadAllAsync(ct)IAsyncEnumerable<ChangeNotification>Read notification stream.
RebootstrapAsync(ct)TaskTrigger manual re-bootstrap.
WaitForBootstrapCompleteAsync(ct)TaskWait until bootstrap finishes.

Returned by the low-level client.SubscribeEventsAsync().

Property / MethodTypeDescription
KindIdushortThe subscribed kind.
ReadAsync(ct)ValueTask<EventNotification>Read the next event notification.
ReadAllAsync(ct)IAsyncEnumerable<EventNotification>Read event notification stream.
TryRead(out notification)boolNon-blocking read attempt.
DisposeAsync()ValueTaskUnsubscribe and release resources.

No bootstrap support. Events are ephemeral.

Returned by client.QueryAsync().

PropertyTypeDescription
StatusQueryStatusAlive, Tombstone, or NotFound.
FieldDataReadOnlyMemory<byte>?Raw field data (only for Alive).
VersionulongEntity version.
SourceSetulongSource bitmask.
ValueDescription
CreatedEntity was created (or re-created from tombstone).
UpdatedEntity field data changed.
DeletedEntity was tombstoned.
BootstrapEntity snapshot from bootstrap scan.
ValueDescription
Created (1)First assert for a previously non-existent entity.
Updated (2)Assert that modifies an existing entity.
Retracted (3)Source retracted its assertion.

EventType.Retracted differs from NotificationType.Deleted: a retraction event fires for every individual retract operation regardless of whether the entity dies, while a Deleted notification only fires when all sources have retracted (entity becomes tombstoned).

ValueDescription
AliveEntity exists and has field data.
TombstoneEntity retracted by all sources, within retention period.
NotFoundEntity never existed or tombstone expired.
ValueDescription
NotRequestedBootstrap was not requested or has not started.
InProgressBOOTSTRAP_BEGIN received, scan in progress.
CompleteBOOTSTRAP_END received, initial bootstrap done.
RebootstrapInProgressRe-bootstrap in progress (after reconnection).
RebootstrapCompleteRe-bootstrap done (after reconnection).
ValueDescription
LiveOnlyResume live-only after reconnect. Gap during disconnect is lost.
FullRe-subscribe with bootstrap after reconnect. Zero-drift guarantee.

Generated by the source generator for each [ConvergenceEntity] struct.

MemberKindDescription
KindNamestatic stringThe kind name registered with the server.
Schemastatic KindSchemaThe field schema used for registration.
FixedFieldDataSizestatic intSize in bytes of the fixed zone (scalars, fixed-length strings/bytes, structs) plus the array directory (4 bytes per variable-length field). For kinds with no variable-length fields, this equals the total field data size.
HasVariableLengthFieldsstatic boolWhether this kind has any Array, VarString, or VarBytes fields.
EntityIdReadOnlyMemory<byte>The 32-byte entity ID.
ComputeFieldDataSize()intCompute the total field data size for this entity instance, including packed array/VarString/VarBytes data. For kinds with no variable-length fields, returns FixedFieldDataSize.
WriteTo(Span<byte>)voidSerialize fields into a buffer of ComputeFieldDataSize() bytes.
ReadFrom(ReadOnlySpan<byte>, ReadOnlyMemory<byte>)static TDeserialize an entity from raw field bytes.
ReadFrom(ReadOnlySpan<byte>, ReadOnlyMemory<byte>, ushort, ushort)static TDeserialize with server layout hints (for evolved schemas).
AttributeTargetDescription
[ConvergenceEntity("Name")]partial structMarks a struct as an entity kind. Accepts optional EventStream = true for per-assert events and DiskBacked = true for disk-backed storage.
[ConvergenceStruct]partial structMarks a struct as an embeddable sub-struct.
[Field(ordinal)]propertyAssigns a stable field ordinal.
[Field(ordinal, MaxLength = N)]string / byte[] propertyField with maximum byte length. Strings default to VarString; bytes default to VarBytes.
[Field(ordinal, MaxLength = N, FixedLength = true)]string / byte[] propertyFixed-length inline storage (String/Bytes).
[Field(ordinal, MaxCount = N)]array propertyField with maximum element count.
PropertyTypeDefaultDescription
Namestring(required)The kind name registered with the server.
EventStreamboolfalseWhen true, the server records per-assert events for this kind.
DiskBackedboolfalseWhen true, entities are stored on disk with an LRU cache instead of entirely in memory. Best for kinds with large populations and small hot working sets. See Defining Entity Kinds.
CacheCapacityuint10,000Initial LRU cache size when DiskBacked = true. The cache grows adaptively if the hit rate drops below 80%. Ignored when DiskBacked is false.
PropertyTypeDefaultDescription
Orderint(required)Stable field ordinal. Determines wire layout position.
MaxLengthint0Maximum byte length for string and byte[] fields. Required for variable-length types.
MaxCountint0Maximum element count for array fields (1 to 1024).
IndexedboolfalseReserved for future secondary index support.
FixedLengthboolfalseWhen true, uses fixed-length inline storage (String/Bytes) instead of the default variable-length storage (VarString/VarBytes).

Built-in entity type for the convergedb_connections system kind. Available via client.Connections. See Client Presence.

PropertyTypeDescription
EntityIdReadOnlyMemory<byte>32-byte entity ID. Byte 0 is the source ID, bytes 1-31 are zero.
NamestringHuman-readable name from ConvergenceOptions.Name. Empty if not set.
LastSeenAtDateTimeOffsetUTC timestamp of the most recent heartbeat or connect.
MethodReturnsDescription
EntityId.FromGuid(Guid)ReadOnlyMemory<byte>32 bytes from a GUID.
EntityId.FromLong(long)ReadOnlyMemory<byte>32 bytes from a long.
EntityId.FromULong(ulong)ReadOnlyMemory<byte>32 bytes from a ulong.
EntityId.FromString(string)ReadOnlyMemory<byte>32 bytes via SHA-256.
EntityId.ToGuid(ReadOnlyMemory<byte>)GuidExtract GUID from entity ID.
EntityId.ToLong(ReadOnlyMemory<byte>)longExtract long from entity ID.