// bitsToRoaringData converts a pairSet into a roaring.Bitmap
// which represents the data within a single shard.
969522
func bitsToRoaringData(ps pairSet) ([]byte, error) {
	bmp := roaring.NewBitmap()
	for j := 0; j < len(ps.columnIDs); j++ {
		bmp.DirectAdd(ps.rowIDs[j]*ShardWidth + (ps.columnIDs[j] % ShardWidth))
	}

	var buf bytes.Buffer
	_, err := bmp.WriteTo(&buf)
	if err != nil {
		return nil, errors.Wrap(err, "writing to buffer")
	}

	return buf.Bytes(), nil
}
664592
func (b *Bitset) ByteAt(index int) byte {
	if index < 0 || index >= b.numBits {
		log.Panicf("Index %d out of range", index)
	}

	var result byte

	for i := index; i < index+8 && i < b.numBits; i++ {
		result <<= 1
		if b.At(i) {
			result |= 1
		}
	}

	return result
}
325903
func (a *Authentication) MarshalBinary() ([]byte, error) {
	// 1 byte:  Protocol
	// 1 byte:  Algorithm
	// 1 byte:  RDM
	// 8 bytes: ReplayDetection
	// N bytes: AuthenticationInformation (can have 0 len byte)
	b := buffer.New(nil)
	b.Write8(a.Protocol)
	b.Write8(a.Algorithm)
	b.Write8(a.RDM)
	b.Write64(a.ReplayDetection)
	b.WriteBytes(a.AuthenticationInformation)

	return b.Data(), nil
}
667779
func (p McGroupSetupAnsPayload) MarshalBinary() ([]byte, error) {
	b := make([]byte, p.Size())
	b[0] = p.McGroupIDHeader.McGroupID & 0x03 // first 2 bits
	if p.McGroupIDHeader.IDError {
		b[0] |= 0x04
	}
	return b, nil
}
186061
func (h Hash) MarshalBinary() (data []byte, err error) {
	if h == (Hash{}) {
		return nil, nil
	}

	if !h.IsValid() {
		return nil, errors.WithStack(InvalidHashError{h})
	}

	return []byte(h.h), nil
}
72484
func (h MerkleHash) MarshalBinary() (data []byte, err error) {
	return h.h.MarshalBinary()
}
250268
func (bh *Header) MarshalBinary() ([]byte, error) {
	b := &bytes.Buffer{}
	err := bh.EncodeBinary(b)
	if err != nil {
		return nil, err
	}
	return b.Bytes(), nil
}
178484
func (m *StatusResponseKvstore) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}
1002219
func (bA *BitArray) MarshalJSON() ([]byte, error) {
	if bA == nil {
		return []byte("null"), nil
	}

	bA.mtx.Lock()
	defer bA.mtx.Unlock()

	bits := `"`
	for i := 0; i < bA.Bits; i++ {
		if bA.getIndex(i) {
			bits += `x`
		} else {
			bits += `_`
		}
	}
	bits += `"`
	return []byte(bits), nil
}
935048
func (o *GetAuthCallbackOKBody) MarshalBinary() ([]byte, error) {
	if o == nil {
		return nil, nil
	}
	return swag.WriteJSON(o)
}
963102
func (i *IAPD) MarshalBinary() ([]byte, error) {
	// 4 bytes: IAID
	// 4 bytes: T1
	// 4 bytes: T2
	// N bytes: options slice byte count
	buf := buffer.New(nil)

	buf.WriteBytes(i.IAID[:])
	buf.Write32(uint32(i.T1 / time.Second))
	buf.Write32(uint32(i.T2 / time.Second))
	opts, err := i.Options.MarshalBinary()
	if err != nil {
		return nil, err
	}
	buf.WriteBytes(opts)

	return buf.Data(), nil
}
126748
func (s *StatusCode) MarshalBinary() ([]byte, error) {
	// 2 bytes: status code
	// N bytes: message
	b := buffer.New(nil)
	b.Write16(uint16(s.Code))
	b.WriteBytes([]byte(s.Message))
	return b.Data(), nil
}
705625
func (m *StatusResponseControllersItems0) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}
645117
func (m *NodeStatus) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}
444535
func (m *StatusResponseControllersItems0Configuration) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}
1005450
func (m *DaemonConfigurationStatus) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}
994413
func (m *StatusResponseClusterNodesItems0PrimaryAddress) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}