PatchbayRuntimeIdentity.fromJson constructor

PatchbayRuntimeIdentity.fromJson(
  1. Map<String, Object?> json
)

Reads one identity answer.

serverVersion and features are read leniently while the four original fields stay strict, and the difference is deliberate: a host that predates them is a supported peer, not a broken one, so their absence has to survive validation and reach the caller as "not reported". A present-but-wrong-typed value is the opposite — nothing in the wire contract can produce it, so it is a host bug and fails closed like any other malformed identity.

Implementation

factory PatchbayRuntimeIdentity.fromJson(Map<String, Object?> json) {
  final schemaVersion = json['schemaVersion'];
  final applicationId = json['applicationId'];
  final appInstanceId = json['appInstanceId'];
  final isolateId = json['isolateId'];
  if (schemaVersion is! int ||
      applicationId is! String ||
      applicationId.isEmpty ||
      appInstanceId is! String ||
      appInstanceId.isEmpty ||
      isolateId is! String ||
      isolateId.isEmpty) {
    throw const PatchbayProtocolException('identityValidationFailed');
  }
  return PatchbayRuntimeIdentity(
    schemaVersion: schemaVersion,
    applicationId: applicationId,
    appInstanceId: appInstanceId,
    isolateId: isolateId,
    serverVersion: patchbayReportedServerVersion(json),
    features: patchbayDeclaredFeatures(json),
  );
}