Everywhere this is used in packets.go, it's immediately followed by `if data == nil` based error handling, so even if it's inlined by the compiler, it always branches twice. `b.length != 0` is the only way this can return nil, so I say manually inline all occurrences (and add a comment), use the buffer directly and drop the superflouus `if` for all 4 occurences.
That's bad from a code style perspective, but the comment should suffice. But it will probably be a little faster and not more complex than it is now.