+ // write number of offsets listed for this reference
+ uint32_t numOffsets = offsets.size();
+ if ( isBigEndian ) SwapEndian_32(numOffsets);
+ fwrite(&numOffsets, sizeof(numOffsets), 1, indexStream);
+
+ // iterate over offset entries
+ vector<BamToolsIndexEntry>::const_iterator offsetIter = offsets.begin();
+ vector<BamToolsIndexEntry>::const_iterator offsetEnd = offsets.end();
+ for ( ; offsetIter != offsetEnd; ++offsetIter ) {
+
+ // get reference index data
+ const BamToolsIndexEntry& entry = (*offsetIter);
+
+ // copy entry data
+ int32_t maxEndPosition = entry.MaxEndPosition;
+ int64_t startOffset = entry.StartOffset;
+ int32_t startPosition = entry.StartPosition;
+
+ // swap endian-ness if necessary
+ if ( isBigEndian ) {
+ SwapEndian_32(maxEndPosition);
+ SwapEndian_64(startOffset);
+ SwapEndian_32(startPosition);
+ }
+
+ // write the reference index entry
+ fwrite(&maxEndPosition, sizeof(maxEndPosition), 1, indexStream);
+ fwrite(&startOffset, sizeof(startOffset), 1, indexStream);
+ fwrite(&startPosition, sizeof(startPosition), 1, indexStream);