package utilities import ( "bytes" "encoding/binary" ) func EncodeIntegerList(data []int) []byte { message := &bytes.Buffer{} buf := make([]byte, binary.MaxVarintLen64) for _, i := range data { n := binary.PutVarint(buf, int64(i)) _, _ = message.Write(buf[:n]) } return message.Bytes() } func DecodeIntegerList(data []byte) []int { buf := bytes.NewBuffer(data) var result []int for { if buf.Len() <= 0 { break } i, err := binary.ReadVarint(buf) if err != nil { //TODO: maybe should error break } result = append(result, int(i)) } return result }