github.com/nyan233/littlerpc@v0.4.6-0.20230316182519-0c8d5c48abaf/core/container/slice_byte.go (about)

     1  package container
     2  
     3  type ByteSlice []byte
     4  
     5  func (s *ByteSlice) Len() int { return len(*s) }
     6  
     7  func (s *ByteSlice) Cap() int { return cap(*s) }
     8  
     9  func (s *ByteSlice) Unique() {
    10  	mark := make(map[byte]struct{}, len(*s))
    11  	var count int
    12  	for _, v := range *s {
    13  		if _, ok := mark[v]; !ok {
    14  			(*s)[count] = v
    15  			mark[v] = struct{}{}
    16  			count++
    17  		}
    18  	}
    19  	*s = (*s)[:count]
    20  }
    21  
    22  func (s *ByteSlice) AppendSingle(v byte) {
    23  	*s = append(*s, v)
    24  }
    25  
    26  func (s *ByteSlice) Append(v []byte) {
    27  	*s = append(*s, v...)
    28  }
    29  
    30  func (s *ByteSlice) AppendS(vs ...byte) {
    31  	*s = append(*s, vs...)
    32  }
    33  
    34  func (s *ByteSlice) Available() bool {
    35  	return s != nil && len(*s) > 0
    36  }
    37  
    38  func (s *ByteSlice) Reset() {
    39  	*s = (*s)[:0]
    40  }