tcp_session: Implement encoding