Skip to content

Commit

Permalink
[IMP]Optimized the C to Go string conversion method
Browse files Browse the repository at this point in the history
  • Loading branch information
randolphcyg committed Dec 26, 2023
1 parent 95f8e91 commit 2a639c6
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions gowireshark.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"log/slog"
"os"
"strconv"
"unsafe"

"github.com/pkg/errors"
)
Expand All @@ -35,10 +34,6 @@ var (
ErrFrameIsBlank = errors.New("frame data is blank")
)

// SINGLEPKTMAXLEN The maximum length limit of the json object of the parsing
// result of a single data packet, which is convenient for converting c char to go string
const SINGLEPKTMAXLEN = 6553500

// DissectResChans dissect result chan map
var DissectResChans = make(map[string]chan FrameDissectRes)

Expand All @@ -58,8 +53,7 @@ func isFileExist(path string) bool {

// CChar2GoStr C string -> Go string
func CChar2GoStr(src *C.char) string {
sLen := int(C.strlen(src))
return string((*[SINGLEPKTMAXLEN]byte)(unsafe.Pointer(src))[:sLen:sLen])
return C.GoStringN(src, C.int(C.strlen(src)))
}

// EpanVersion get epan module's version
Expand Down

0 comments on commit 2a639c6

Please sign in to comment.