Add this as a utility method in Spark.Utils (maybe writeByteBuffer)