[utils] rewrite local_buff
[test] add test, fix bsearch