The current buffer reading funcs will return numbers of the same size that were read. Shorts return a 16 bit number, int/long returns 32 bit numbers etc. This results in needing to use casting funcs all over the place. Change these functions to return standard ints and handle the length internally.