serialize binary tree