def bencode(obj):
    buf = BytesIO()
    b = BCodec(buf)
    b.encode(obj)
    return buf.bytes()