merged encode/decode into a duplex stream