You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

serialization.go 814B

12345678910111213141516171819202122232425262728293031323334
  1. package roaring
  2. import (
  3. "encoding/binary"
  4. "io"
  5. "github.com/tinylib/msgp/msgp"
  6. )
  7. // writeTo for runContainer16 follows this
  8. // spec: https://github.com/RoaringBitmap/RoaringFormatSpec
  9. //
  10. func (b *runContainer16) writeTo(stream io.Writer) (int, error) {
  11. buf := make([]byte, 2+4*len(b.iv))
  12. binary.LittleEndian.PutUint16(buf[0:], uint16(len(b.iv)))
  13. for i, v := range b.iv {
  14. binary.LittleEndian.PutUint16(buf[2+i*4:], v.start)
  15. binary.LittleEndian.PutUint16(buf[2+2+i*4:], v.length)
  16. }
  17. return stream.Write(buf)
  18. }
  19. func (b *runContainer16) writeToMsgpack(stream io.Writer) (int, error) {
  20. bts, err := b.MarshalMsg(nil)
  21. if err != nil {
  22. return 0, err
  23. }
  24. return stream.Write(bts)
  25. }
  26. func (b *runContainer16) readFromMsgpack(stream io.Reader) (int, error) {
  27. err := msgp.Decode(stream, b)
  28. return 0, err
  29. }