Extending a bijection recently introduced by Poulalhon and Schaeffer [15] for triangulations of the sphere we design an efficient algorithm for encoding (topological) triangulations and bipartite quadrangulations on an orientable surface of fixed topology (given by the genus g and number of boundaries b). To our knowledge, our encoding procedure is the first to be asymptotically optimal (in the information theory sense) with respect to two natural parameters, the number n of inner vertices and the number k of boundary vertices.