this is where i have a question. Now this serialization format should comply with the one in the ParrayDataType where the normal array serialization occurs and only then while doing rs.getArray() the toObject would work to retrieve back this as an PhoenixArray. 
If that is the case then our format should be same as what we did in the ParrayDataType.bytesFromByteBuffer() where we handle to cases, short and Int.  Ideally all those things should be done for the varlength array in this case also. So track the offset and add it in the stream and above for all this I need to calculate the size of every element in the array for which I need to do a toByte on every element and find the size and then serialize it in the format as in ParrayDataType.bytesFromByteBuffer() .