v0.1.0 efficiently/correctly set dlen in buffer codec

  update the bytes-written to *dlen just before returning

  initialize *dlen to zero as soon as the call is entered

  allow dlen to be NULL for users who don't need it