<commit_before>//Package goshark use tshark to decode IP packet and get data struct to analysis packet.
package goshark

import (
	"bufio"
	"bytes"
	"encoding/xml"
	"errors"
	"fmt"
	"io"
	"log"
	"os/exec"
	"strings"
	"sync"
)

//Data struct of IP packet
type Field struct {
	Field  map[string]string
	Childs []*Field
	Parent *Field
}

type Decoder struct {
	Cmd         *exec.Cmd
	W           sync.WaitGroup
	Reader      io.ReadCloser
	BufioReader *bufio.Reader
}

//Implements Decoder
func NewDecoder() (decoder *Decoder) {
	decoder = &Decoder{}
	return decoder
}

//Start decoding. When finished, should use DecodeEnd
//to close decoding. Use defer DecodeEnd after DecodeStart
//success.
//Return err ???
func (d *Decoder) DecodeStart(file string) (err error) {

	cmd := exec.Command("tshark", "-T", "pdml", "-r", file)

	d.Cmd = cmd
	d.Reader, err = cmd.StdoutPipe()
	if err != nil {
		return
	}

	d.BufioReader = bufio.NewReader(d.Reader)

	err = cmd.Start()
	if err != nil {
		return
	}

	return
}

//Close decoding
func (d *Decoder) DecodeEnd() error {
	if err := d.Cmd.Wait(); err != nil {
		log.Println("cmd wait fail:", err)
		return err
	}

	return nil
}

//Get the one packet from Decoder. When at then end of file,
//get error io.EOF with nil field.
func (d *Decoder) NextPacket() (field *Field, err error) {
	var out []byte
	var startRecord bool = false

	for {
		line, _, err := d.BufioReader.ReadLine()
		if err == io.EOF {<commit_msg>change Decoder items to private<commit_after>//Package goshark use tshark to decode IP packet and get data struct to analysis packet.
package goshark

import (
	"bufio"
	"bytes"
	"encoding/xml"
	"errors"
	"fmt"
	"io"
	"log"
	"os/exec"
	"strings"
)

//Data struct of IP packet
type Field struct {
	Field  map[string]string
	Childs []*Field
	Parent *Field
}

type Decoder struct {
	cmd         *exec.Cmd
	reader      io.ReadCloser
	bufioReader *bufio.Reader
}

//Implements Decoder
func NewDecoder() (decoder *Decoder) {
	decoder = &Decoder{}
	return decoder
}

//Start decoding. When finished, should use DecodeEnd
//to close decoding. Use defer DecodeEnd after DecodeStart
//success.
//Return err ???
func (d *Decoder) DecodeStart(file string) (err error) {

	cmd := exec.Command("tshark", "-T", "pdml", "-r", file)

	d.cmd = cmd
	d.reader, err = cmd.StdoutPipe()
	if err != nil {
		return
	}

	d.bufioReader = bufio.NewReader(d.reader)

	err = cmd.Start()
	if err != nil {
		return
	}

	return
}

//Close decoding
func (d *Decoder) DecodeEnd() error {
	if err := d.cmd.Wait(); err != nil {
		log.Println("cmd wait fail:", err)
		return err
	}

	return nil
}

//Get the one packet from Decoder. When at then end of file,
//get error io.EOF with nil field.
func (d *Decoder) NextPacket() (field *Field, err error) {
	var out []byte
	var startRecord bool = false

	for {
		line, _, err := d.bufioReader.ReadLine()
		if err == io.EOF {
{'fraction_non_alphanumeric': 0.1315058986814712, 'fraction_numerical': 0.0, 'mean_word_length': 3.2965722801788377, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2514535', 'n_tokens_mistral': 1067, 'n_tokens_neox': 1026, 'n_words': 345}