implement writeToFrame and serialize