porting types/type util function (bytes) from optimize branch.