entry_to_bytes and its friends were called many times (eg. entry_to_bytes
alone was called 40k times while indexing 500 origins with the metadata
indexer), and its use of isinstance used a non-negligible amount of
CPU time.
Instead of using *_to_bytes function as post-processing on all bits of
data returned by postgresql, this patch tells psycopg to use a new
typecast_bytea function when needed (in adapt_conn).
This function deffers the decoding work to psycopg2, which returns a
memoryview, which is turned into bytes.