buffer: consolidate write encoding