encodeArg method
Encode a single argument
Implementation
@override
dynamic encodeArg(dynamic arg) {
if (isNullOrUndefined(arg)) {
return null;
}
if (arg is Uint8List) {
return {
'_type': ArgType.base64.value,
'data': base64Encode(arg),
};
}
if (isInstance(arg)) {
String? id = _instanceMapId[arg];
if (id == null) {
id = getUuid('instance');
registerProxyInstance(id, arg);
}
return {
'_type': ArgType.instance.value,
'_instanceId': id,
};
}
if (arg is NativeClass) {
registerProxyInstance(arg.$resource.instanceId, arg);
return {
'_type': ArgType.instance.value,
'_instanceId': arg.$resource.instanceId,
};
}
if (isFunction(arg)) {
String? id = _callbackMapId[arg];
if (id == null) {
id = getUuid('callback');
_registerCallback(id, arg);
}
return {
'_type': ArgType.callback.value,
'_callbackId': id,
};
}
if (isArray(arg)) {
return (arg as List).map((item) => encodeArg(item)).toList();
}
if (isObject(arg)) {
return (arg as Map).map((key, value) => MapEntry(key, encodeArg(value)));
}
// get enum value
if (arg is Enum) {
try {
final value = (arg as dynamic).value;
if (value != null) {
return value;
}
return arg;
} catch (e) {
return arg;
}
}
return arg;
}