Move a bunch of endpoint serialization logic into Channel, where it belongs.

R=yzshen@chromium.org

Review URL: https://codereview.chromium.org/802763002