I am a newbie and would like to know why the data in pcapBytes is incomplete after append. Is it because the data is overwritten or the append fails? Can you help me analyze the BUG of the program?
var pcapBytes map[string][][]byte
func initCache(){
pcapBytes := make(map[string][][]byte)
for name,frames in range pcapInfos{
var pcapData [][]byte
var buff bytes.Buffer
buff.Grow(4096)
for _, frame := range frames {
if buff.Len()+frame.Length > 4096 {
pcapData = append(pcapData, buff.Bytes())
buff.Reset()
}
_, err := buff.Write(frame.Data)
if err != nil {
log.Fatal(err)
}
}
if buff.Len() > 0 {
pcapData = append(pcapData, buff.Bytes())
}
pcapBytes[name] = pcapData
}
}