request.dart 657 B

1234567891011121314151617181920212223242526272829
  1. class JsonRpcRequest {
  2. static const String _serverVersion = '2.0';
  3. final String method;
  4. final Object? args;
  5. final bool notify;
  6. int? get id => !this.notify ? this.hashCode : null;
  7. JsonRpcRequest(this.method, this.args, {this.notify = false});
  8. Map<String, dynamic> toJson() {
  9. var map = <String, dynamic>{};
  10. map = {
  11. 'jsonrpc': _serverVersion,
  12. 'method': method,
  13. 'params': (args == null)
  14. ? []
  15. : (args is List || args is Map)
  16. ? args
  17. : [args]
  18. };
  19. if (!notify) map['id'] = id;
  20. return map;
  21. }
  22. @override
  23. String toString() => 'JsonRpcRequest: ${toJson()}';
  24. }