function bbhArray = serialize(data, optBufSize, profEnabled)
%parallel.internal.pool.serialize - Serialize data to an array of ByteBufferHandles
%   for transmission

%   Copyright 2012-2019 The MathWorks, Inc.

if nargin < 3 || profEnabled
    [id, profEnabled] = parallel.internal.pool.serializationProfiling('serialize', true, [], -1);
end
serialized = distcompserialize64(data);
if nargin < 2 || isempty(optBufSize)
    bbhArray = distcompMakeByteBufferHandles(serialized);
else
    bbhArray = distcompMakeByteBufferHandles(serialized, optBufSize);
end
if profEnabled
    parallel.internal.pool.serializationProfiling('serialize', false, id, numel(serialized));
end
end
