serialize: extract initial check out of while loops
serialize: extract initial check out of while loops

No need to repeat the condition at every loop.

gopro/gopro-lib-node.gl,gopro/gopro-lib-node.gl,gopro/gopro-lib-node.gl,gopro/gopro-lib-node.gl