fromWire static method
Decode a plain-JSON wire object. Defaults fragmentation_supported = false, ordered_reliable = true, features = [] when absent (mirrors
the lazily-rs serde defaults).
Implementation
static CapabilityHandshake fromWire(Object? value) {
final obj = value is Map ? value.cast<String, Object?>() : <String, Object?>{};
int field(Object? v, String name) {
if (v is! int || v < 0) {
throw FormatException(
'$name must be a non-negative integer, got ${v?.runtimeType}');
}
return v;
}
return CapabilityHandshake(
peerId: field(obj['peer_id'], 'peer_id'),
sessionId: (obj['session_id'] ?? '') as String,
protocolId: (obj['protocol_id'] ?? kProtocolId) as String,
protocolMajorVersion:
(obj['protocol_major_version'] ?? kProtocolMajorVersion) as int,
codec: (obj['codec'] ?? kDefaultCodec) as String,
maxFrameSize:
field(obj['max_frame_size'] ?? kDefaultMaxFrameSize, 'max_frame_size'),
fragmentationSupported: (obj['fragmentation_supported'] ?? false) as bool,
orderedReliable: (obj['ordered_reliable'] ?? true) as bool,
features: obj['features'] is List
? (obj['features'] as List).map((e) => e.toString()).toList()
: const [],
);
}