github.com/coyove/sdss@v0.0.0-20231129015646-c2ec58cca6a2/contrib/roaring/serialization.go (about) 1 package roaring 2 3 import ( 4 "encoding/binary" 5 "io" 6 ) 7 8 // writeTo for runContainer16 follows this 9 // spec: https://github.com/RoaringBitmap/RoaringFormatSpec 10 // 11 func (b *runContainer16) writeTo(stream io.Writer) (int, error) { 12 buf := make([]byte, 2+4*len(b.iv)) 13 binary.LittleEndian.PutUint16(buf[0:], uint16(len(b.iv))) 14 for i, v := range b.iv { 15 binary.LittleEndian.PutUint16(buf[2+i*4:], v.start) 16 binary.LittleEndian.PutUint16(buf[2+2+i*4:], v.length) 17 } 18 return stream.Write(buf) 19 }