I have done this now.  But not in the above way instead

     ptr.set(byteStream.getBuffer(), 0, estimatedSize + elementLength);

where am tracking the elementLength incase of variable length array.  So that as we don't know the real size of the byteStream, by doing this we avoid the unnecessary 0 that gets added.  Because we have now changed the header info to the end of the serialization having this 0 would cause error.