refactor packet read handling to case switch from if else