function to encode node data