factor out octet stream reader in a helper