Skip to content

Commit

Permalink
Fix array extend. #10
Browse files Browse the repository at this point in the history
  • Loading branch information
phaag committed May 20, 2024
1 parent 12a0a18 commit 758b864
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
4 changes: 4 additions & 0 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func (nfFile *NfFile) addExporterStat(record []byte) {
packets := binary.LittleEndian.Uint64(record[offset+8 : offset+16]) // number of packets sent by this exporter
flows := binary.LittleEndian.Uint64(record[offset+16 : offset+24]) // number of flows sent by this exporter
offset += 24
if int(sysId) >= len(nfFile.ExporterList) {
fmt.Printf("Invalid Exporter id: %d\n", sysId)
return
}
if nfFile.ExporterList[sysId].SysId == uint16(sysId) {
nfFile.ExporterList[sysId].SequenceFailures += sequenceFailures
nfFile.ExporterList[sysId].Packets += packets
Expand Down
7 changes: 7 additions & 0 deletions nffile.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ func (nfFile *NfFile) ReadDataBlocks() (chan DataBlock, error) {
// fmt.Printf("nfFile read block header: %v", err)
return
}
// fmt.Printf("Datablock type: %d, size: %d records: %d\n", dataBlock.Header.Type, dataBlock.Header.Size, dataBlock.Header.NumRecords)
if dataBlock.Header.Type != 3 {
if _, err := nfFile.file.Seek(int64(dataBlock.Header.Size), os.SEEK_CUR); err != nil {
fmt.Fprintf(os.Stderr, "file seek error: %v\n", err)
}
continue
}
var err error
dataBlock.Data, err = nfFile.uncompressBlock(&dataBlock.Header)
// fmt.Printf("nfFile uncompress block: %v", err)
Expand Down
10 changes: 9 additions & 1 deletion nffileV1.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,15 @@ func (nfFile *NfFile) openV1() error {
nfFile.Header.Version = nfFileV1Header.Version
nfFile.Header.NfVersion = 0x106
nfFile.Header.Created = 0
nfFile.Header.Compression = 0
compression := 0
if nfFileV1Header.Flags&0x1 == 1 {
compression = 1 // LO0
} else if nfFileV1Header.Flags&0x8 == 0x8 {
compression = 2 // BZIP2
} else if nfFileV1Header.Flags&0x10 == 0x10 {
compression = 3 // LZ4
}
nfFile.Header.Compression = uint8(compression)
nfFile.Header.Encryption = 0
nfFile.Header.AppendixBlocks = 0
nfFile.Header.Unused = 0
Expand Down
8 changes: 5 additions & 3 deletions orderby.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ func (recordChain *RecordChain) OrderBy(orderBy string, direction int) *RecordCh
var cnt uint32 = 0
for record := range readChan {
if uint32(arrayLen)-cnt == 0 {
// double array, if exhausted
sortArray = append(make([]sortRecord, 2*arrayLen), sortArray...)
recordArray = append(make([]*FlowRecordV3, 2*arrayLen), recordArray...)
// extend array, if exhausted
// sortArray
sortArray = append(sortArray, make([]sortRecord, 2*arrayLen)...)
// recordArray
recordArray = append(recordArray, make([]*FlowRecordV3, 2*arrayLen)...)

// use new len of array. Go may assign more memory than requested
// so use actual len
Expand Down

0 comments on commit 758b864

Please sign in to comment.