You take a stream/buffer of binary data. The start of your data is a "Page", which has a header followed by data.
You need to read the following data from the header (see https://xiph.org/ogg/doc/framing.html for more detail)
capture_pattern
- bytes 0 to 3, must read OggSstream_structure_version
- byte 4, must be 0header_type_flag
- byte 5, a bitflag that tells you metadata about the page (is it a new packet? is a packet continued here? is it the first/last page of the stream?)absolute granule position
- bytes 6 to 13, not needed unless you want seekingstream serial number
- bytes 14 to 17, a serial number given to each stream contained in the Ogg file. This is important for playing Ogg files that contain other streams, such as video or cover art. You need to identify and only bother parsing the Opus stream.