Encode/decode to/from references to readers

I borrowed the pattern used in the json encoder in the standard library. The code uses an unsafe block, but I guess it can be removed whenever https://github.com/rust-lang/rust/issues/14302 is resolved. All the tests pass at least :P