add entity encoding & tests for it