function [OK, serKey, serWarnings] = remoteStore(serVal, arrayHolderToClear)
% Add value to value store and return storage key or error
% key, warnings, and value are all serialized

% Copyright 2008-2020 The MathWorks, Inc.

keysToClear = int64.empty();
if ~isempty(arrayHolderToClear)
    keysToClear = arrayHolderToClear.array();
end

wc = parallel.internal.general.WarningsCollector();
try
    val = parallel.internal.pool.deserialize(serVal);
    [OK, key] = spmdlang.remoteStorePlain(val, keysToClear);
    serKey = parallel.internal.pool.serialize(key);
catch E
    OK = false;
    serKey = parallel.internal.pool.serialize(E);
end

serWarnings = parallel.internal.pool.serialize(wc.Warnings);
end
