bufferevent: refactor to use type check macros (cherry picked from commit 92cc0b9c3db38088f79c5d1e432c429fbc366968)