A BSON encoder/decoder taken from the Vitess project.