github.com/sequix/cortex@v1.1.6/pkg/chunk/storage/bytes.go (about)

     1  package storage
     2  
     3  import (
     4  	"bytes"
     5  )
     6  
     7  // Bytes exists to stop proto copying the byte array
     8  type Bytes []byte
     9  
    10  // Marshal just returns bs
    11  func (bs *Bytes) Marshal() ([]byte, error) {
    12  	return []byte(*bs), nil
    13  }
    14  
    15  // MarshalTo copies Bytes to data
    16  func (bs *Bytes) MarshalTo(data []byte) (n int, err error) {
    17  	return copy(data, *bs), nil
    18  }
    19  
    20  // Unmarshal updates Bytes to be data, without a copy
    21  func (bs *Bytes) Unmarshal(data []byte) error {
    22  	*bs = data
    23  	return nil
    24  }
    25  
    26  // Size returns the length of Bytes
    27  func (bs *Bytes) Size() int {
    28  	return len(*bs)
    29  }
    30  
    31  // Equal returns true if other equals Bytes
    32  func (bs *Bytes) Equal(other Bytes) bool {
    33  	return bytes.Equal(*bs, other)
    34  }
    35  
    36  // Compare Bytes to other
    37  func (bs *Bytes) Compare(other Bytes) int {
    38  	return bytes.Compare(*bs, other)
    39  }