encoder: initial port from bibencode