Skip to content

Commit

Permalink
Merge pull request #96 from acados/any2jd_try
Browse files Browse the repository at this point in the history
any2jd: raise error if object cannot be converted
  • Loading branch information
fangq authored Aug 18, 2024
2 parents 46d48c7 + e0fe08e commit 288dc92
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions jdataencode.m
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,15 @@

%% -------------------------------------------------------------------------
function newitem = any2jd(item, varargin)

N = @(x) N_(x, varargin{:});
newitem.(N('_DataInfo_')) = struct('MATLABObjectClass', class(item), 'MATLABObjectSize', size(item));
newitem.(N('_ByteStream_')) = getByteStreamFromArray(item); % use undocumented matlab function
if (varargin{1}.base64)
newitem.(N('_ByteStream_')) = char(base64encode(newitem.(N('_ByteStream_'))));
try
N = @(x) N_(x, varargin{:});
newitem.(N('_DataInfo_')) = struct('MATLABObjectClass', class(item), 'MATLABObjectSize', size(item));
newitem.(N('_ByteStream_')) = getByteStreamFromArray(item); % use undocumented matlab function
if (varargin{1}.base64)
newitem.(N('_ByteStream_')) = char(base64encode(newitem.(N('_ByteStream_'))));
end
catch
error('any2jd: failed to convert object of type %s', class(item));
end

%% -------------------------------------------------------------------------
Expand Down

0 comments on commit 288dc92

Please sign in to comment.