better conn/encoding

Summary: for initial review

Test Plan: manual, unit tests.

Reviewers: ben

Reviewed By: ben

Subscribers: john, Engineering

Differential Revision: https://phabricator.poptip.com/D2986