Skip to content

Commit

Permalink
Merge pull request #121 from muzzammilshahid/null-args-kwargs
Browse files Browse the repository at this point in the history
Don't assign null to empty args and kwargs
  • Loading branch information
muzzammilshahid authored Jul 8, 2024
2 parents f776a57 + f7cfc7a commit 15a2444
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 100 deletions.
35 changes: 26 additions & 9 deletions lib/src/messages/abort.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ abstract class IAbortFields {

String get reason;

List<dynamic> get args;
List<dynamic>? get args;

Map<String, dynamic> get kwargs;
Map<String, dynamic>? get kwargs;
}

class AbortFields implements IAbortFields {
Expand All @@ -18,14 +18,14 @@ class AbortFields implements IAbortFields {
this._reason, {
List<dynamic>? args,
Map<String, dynamic>? kwargs,
}) : _args = args ?? [],
_kwargs = kwargs ?? {};
}) : _args = args,
_kwargs = kwargs;

final Map<String, dynamic> _details;
final String _reason;

final List<dynamic> _args;
final Map<String, dynamic> _kwargs;
final List<dynamic>? _args;
final Map<String, dynamic>? _kwargs;

@override
Map<String, dynamic> get details => _details;
Expand All @@ -34,10 +34,10 @@ class AbortFields implements IAbortFields {
String get reason => _reason;

@override
List get args => _args;
List? get args => _args;

@override
Map<String, dynamic> get kwargs => _kwargs;
Map<String, dynamic>? get kwargs => _kwargs;
}

class Abort implements Message {
Expand Down Expand Up @@ -69,6 +69,10 @@ class Abort implements Message {

String get reason => _abortFields.reason;

List<dynamic>? get args => _abortFields.args;

Map<String, dynamic>? get kwargs => _abortFields.kwargs;

static Abort parse(final List<dynamic> message) {
var fields = validateMessage(message, id, text, _validationSpec);

Expand All @@ -77,7 +81,20 @@ class Abort implements Message {

@override
List<dynamic> marshal() {
return [id, details, reason];
List<dynamic> message = [id, details, reason];

if (args != null) {
message.add(args);
}

if (kwargs != null) {
if (args == null) {
message.add([]);
}
message.add(kwargs);
}

return message;
}

@override
Expand Down
26 changes: 13 additions & 13 deletions lib/src/messages/call.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ abstract class ICallFields {

String get uri;

List<dynamic> get args;
List<dynamic>? get args;

Map<String, dynamic> get kwargs;
Map<String, dynamic>? get kwargs;

Map<String, dynamic> get options;
}
Expand All @@ -21,14 +21,14 @@ class CallFields implements ICallFields {
List<dynamic>? args,
Map<String, dynamic>? kwargs,
Map<String, dynamic>? options,
}) : _args = args ?? [],
_kwargs = kwargs ?? {},
}) : _args = args,
_kwargs = kwargs,
_options = options ?? {};

final int _requestID;
final String _uri;
final List<dynamic> _args;
final Map<String, dynamic> _kwargs;
final List<dynamic>? _args;
final Map<String, dynamic>? _kwargs;
final Map<String, dynamic> _options;

@override
Expand All @@ -38,10 +38,10 @@ class CallFields implements ICallFields {
String get uri => _uri;

@override
List get args => _args;
List? get args => _args;

@override
Map<String, dynamic> get kwargs => _kwargs;
Map<String, dynamic>? get kwargs => _kwargs;

@override
Map<String, dynamic> get options => _options;
Expand Down Expand Up @@ -77,9 +77,9 @@ class Call implements Message {

String get uri => _callFields.uri;

List<dynamic> get args => _callFields.args;
List<dynamic>? get args => _callFields.args;

Map<String, dynamic> get kwargs => _callFields.kwargs;
Map<String, dynamic>? get kwargs => _callFields.kwargs;

Map<String, dynamic> get options => _callFields.options;

Expand All @@ -92,12 +92,12 @@ class Call implements Message {
@override
List<dynamic> marshal() {
List<dynamic> message = [id, requestID, options, uri];
if (args.isNotEmpty) {
if (args != null) {
message.add(args);
}

if (kwargs.isNotEmpty) {
if (args.isEmpty) {
if (kwargs != null) {
if (args == null) {
message.add([]);
}
message.add(kwargs);
Expand Down
26 changes: 13 additions & 13 deletions lib/src/messages/error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ abstract class IErrorFields {

String get uri;

List<dynamic> get args;
List<dynamic>? get args;

Map<String, dynamic> get kwargs;
Map<String, dynamic>? get kwargs;

Map<String, dynamic> get details;
}
Expand All @@ -24,15 +24,15 @@ class ErrorFields implements IErrorFields {
List<dynamic>? args,
Map<String, dynamic>? kwargs,
Map<String, dynamic>? details,
}) : _args = args ?? [],
_kwargs = kwargs ?? {},
}) : _args = args,
_kwargs = kwargs,
_details = details ?? {};

final int _msgType;
final int _requestID;
final String _uri;
final List<dynamic> _args;
final Map<String, dynamic> _kwargs;
final List<dynamic>? _args;
final Map<String, dynamic>? _kwargs;
final Map<String, dynamic> _details;

@override
Expand All @@ -45,10 +45,10 @@ class ErrorFields implements IErrorFields {
String get uri => _uri;

@override
List get args => _args;
List? get args => _args;

@override
Map<String, dynamic> get kwargs => _kwargs;
Map<String, dynamic>? get kwargs => _kwargs;

@override
Map<String, dynamic> get details => _details;
Expand Down Expand Up @@ -94,9 +94,9 @@ class Error implements Message {

String get uri => _errorFields.uri;

List<dynamic> get args => _errorFields.args;
List<dynamic>? get args => _errorFields.args;

Map<String, dynamic> get kwargs => _errorFields.kwargs;
Map<String, dynamic>? get kwargs => _errorFields.kwargs;

Map<String, dynamic> get details => _errorFields.details;

Expand All @@ -116,12 +116,12 @@ class Error implements Message {
@override
List<dynamic> marshal() {
List<dynamic> message = [id, msgType, requestID, details, uri];
if (args.isNotEmpty) {
if (args != null) {
message.add(args);
}

if (kwargs.isNotEmpty) {
if (args.isEmpty) {
if (kwargs != null) {
if (args == null) {
message.add([]);
}
message.add(kwargs);
Expand Down
26 changes: 13 additions & 13 deletions lib/src/messages/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ abstract class IEventFields {

int get publicationID;

List<dynamic> get args;
List<dynamic>? get args;

Map<String, dynamic> get kwargs;
Map<String, dynamic>? get kwargs;

Map<String, dynamic> get details;
}
Expand All @@ -21,14 +21,14 @@ class EventFields implements IEventFields {
List<dynamic>? args,
Map<String, dynamic>? kwargs,
Map<String, dynamic>? details,
}) : _args = args ?? [],
_kwargs = kwargs ?? {},
}) : _args = args,
_kwargs = kwargs,
_details = details ?? {};

final int _subscriptionID;
final int _publicationID;
final List<dynamic> _args;
final Map<String, dynamic> _kwargs;
final List<dynamic>? _args;
final Map<String, dynamic>? _kwargs;
final Map<String, dynamic> _details;

@override
Expand All @@ -38,10 +38,10 @@ class EventFields implements IEventFields {
int get publicationID => _publicationID;

@override
List get args => _args;
List? get args => _args;

@override
Map<String, dynamic> get kwargs => _kwargs;
Map<String, dynamic>? get kwargs => _kwargs;

@override
Map<String, dynamic> get details => _details;
Expand Down Expand Up @@ -83,9 +83,9 @@ class Event implements Message {

int get publicationID => _eventFields.publicationID;

List<dynamic> get args => _eventFields.args;
List<dynamic>? get args => _eventFields.args;

Map<String, dynamic> get kwargs => _eventFields.kwargs;
Map<String, dynamic>? get kwargs => _eventFields.kwargs;

Map<String, dynamic> get details => _eventFields.details;

Expand All @@ -104,12 +104,12 @@ class Event implements Message {
@override
List<dynamic> marshal() {
List<dynamic> message = [id, subscriptionID, publicationID, details];
if (args.isNotEmpty) {
if (args != null) {
message.add(args);
}

if (kwargs.isNotEmpty) {
if (args.isEmpty) {
if (kwargs != null) {
if (args == null) {
message.add([]);
}
message.add(kwargs);
Expand Down
26 changes: 13 additions & 13 deletions lib/src/messages/invocation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ abstract class IInvocationFields {

int get registrationID;

List<dynamic> get args;
List<dynamic>? get args;

Map<String, dynamic> get kwargs;
Map<String, dynamic>? get kwargs;

Map<String, dynamic> get details;
}
Expand All @@ -21,14 +21,14 @@ class InvocationFields implements IInvocationFields {
List<dynamic>? args,
Map<String, dynamic>? kwargs,
Map<String, dynamic>? details,
}) : _args = args ?? [],
_kwargs = kwargs ?? {},
}) : _args = args,
_kwargs = kwargs,
_details = details ?? {};

final int _requestID;
final int _registrationID;
final List<dynamic> _args;
final Map<String, dynamic> _kwargs;
final List<dynamic>? _args;
final Map<String, dynamic>? _kwargs;
final Map<String, dynamic> _details;

@override
Expand All @@ -38,10 +38,10 @@ class InvocationFields implements IInvocationFields {
int get registrationID => _registrationID;

@override
List get args => _args;
List? get args => _args;

@override
Map<String, dynamic> get kwargs => _kwargs;
Map<String, dynamic>? get kwargs => _kwargs;

@override
Map<String, dynamic> get details => _details;
Expand Down Expand Up @@ -83,9 +83,9 @@ class Invocation implements Message {

int get registrationID => _invocationFields.registrationID;

List<dynamic> get args => _invocationFields.args;
List<dynamic>? get args => _invocationFields.args;

Map<String, dynamic> get kwargs => _invocationFields.kwargs;
Map<String, dynamic>? get kwargs => _invocationFields.kwargs;

Map<String, dynamic> get details => _invocationFields.details;

Expand All @@ -104,12 +104,12 @@ class Invocation implements Message {
@override
List<dynamic> marshal() {
List<dynamic> message = [id, requestID, registrationID, details];
if (args.isNotEmpty) {
if (args != null) {
message.add(args);
}

if (kwargs.isNotEmpty) {
if (args.isEmpty) {
if (kwargs != null) {
if (args == null) {
message.add([]);
}
message.add(kwargs);
Expand Down
Loading

0 comments on commit 15a2444

Please sign in to comment.