Skip to content

Commit

Permalink
feat: parsing symbols using native function (#4)
Browse files Browse the repository at this point in the history
* feat: parsing symbols using native function

* feat: parsing symbols using native function
add release
  • Loading branch information
kosyloa authored Jan 31, 2024
1 parent 981aadd commit 5ae927c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 19 deletions.
6 changes: 3 additions & 3 deletions cmd/tools/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package main
import (
"fmt"
"github.com/dxfeed/dxfeed-graal-go-api/pkg/api"
"github.com/dxfeed/dxfeed-graal-go-api/pkg/common"
"github.com/dxfeed/dxfeed-graal-go-api/pkg/events/eventcodes"
"github.com/dxfeed/dxfeed-graal-go-api/pkg/events/profile"
"github.com/dxfeed/dxfeed-graal-go-api/pkg/events/quote"
"github.com/dxfeed/dxfeed-graal-go-api/pkg/events/timeandsale"
"github.com/dxfeed/dxfeed-graal-go-api/pkg/parser"
"math"
"os"
"time"
Expand Down Expand Up @@ -46,8 +46,8 @@ func (c Connect) Run(args []string) {
}

address := arguments[0]
symbols := common.ParseSymbols(arguments[2])
types := common.ParseEventTypes(arguments[1])
symbols := parser.ParseSymbols(arguments[2])
types := parser.ParseEventTypes(arguments[1])
err := connect(address, types, symbols, dxarguments.properties(), dxarguments.forceStream(), dxarguments.isQuite())
if err != nil {
fmt.Printf("Error during connect: %v", err)
Expand Down
5 changes: 3 additions & 2 deletions cmd/tools/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/dxfeed/dxfeed-graal-go-api/pkg/events/profile"
"github.com/dxfeed/dxfeed-graal-go-api/pkg/events/quote"
"github.com/dxfeed/dxfeed-graal-go-api/pkg/events/timeandsale"
"github.com/dxfeed/dxfeed-graal-go-api/pkg/parser"
"os"
)

Expand Down Expand Up @@ -49,8 +50,8 @@ func (c Dump) Run(args []string) {
os.Exit(0)
}
inputFile := arguments[0]
symbols := common.ParseSymbols(arguments[2])
types := common.ParseEventTypes(arguments[1])
symbols := parser.ParseSymbols(arguments[2])
types := parser.ParseEventTypes(arguments[1])

err := dump(inputFile, tape, symbols, types, properties, isQuite)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/tools/perftest.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package main
import (
"fmt"
"github.com/dxfeed/dxfeed-graal-go-api/pkg/api"
"github.com/dxfeed/dxfeed-graal-go-api/pkg/common"
"github.com/dxfeed/dxfeed-graal-go-api/pkg/events/eventcodes"
"github.com/dxfeed/dxfeed-graal-go-api/pkg/events/quote"
"github.com/dxfeed/dxfeed-graal-go-api/pkg/events/timeandsale"
"github.com/dxfeed/dxfeed-graal-go-api/pkg/parser"
"math"
"os"
"sync"
Expand Down Expand Up @@ -42,8 +42,8 @@ func (c PerfTest) Run(args []string) {
os.Exit(0)
}
address := arguments[0]
types := common.ParseEventTypes(arguments[1])
symbols := common.ParseSymbols(arguments[2])
types := parser.ParseEventTypes(arguments[1])
symbols := parser.ParseSymbols(arguments[2])

err := perf(address, types, symbols, dxarguments.forceStream())
if err != nil {
Expand Down
36 changes: 36 additions & 0 deletions internal/native/symbol_parser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package native

/*
#include "dxfg_api.h"
#include <stdlib.h>
*/
import "C"
import "unsafe"

func ParseSymbols(symbols string) ([]any, error) {
var result []any
err := executeInIsolateThread(func(thread *isolateThread) error {
symbolsPtr := C.CString(symbols)
defer C.free(unsafe.Pointer(symbolsPtr))
return checkCall(func() {
resultPtr := C.dxfg_Tools_parseSymbols(thread.ptr, symbolsPtr)
defer C.dxfg_CList_String_release(thread.ptr, resultPtr)

if resultPtr == nil || resultPtr.elements == nil || int(resultPtr.size) == 0 {
return
}

size := int(resultPtr.size)
list := make([]any, size)
elementsSlice := unsafe.Slice(resultPtr.elements, C.size_t(resultPtr.size))

for i, event := range elementsSlice {
symbol := C.GoString(event)
list[i] = symbol
}
result = list
})
})

return result, err
}
19 changes: 8 additions & 11 deletions pkg/common/argument_parser.go → pkg/parser/argument_parser.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
package common
package parser

import (
"github.com/dxfeed/dxfeed-graal-go-api/internal/native"
"github.com/dxfeed/dxfeed-graal-go-api/pkg/api/Osub"
"github.com/dxfeed/dxfeed-graal-go-api/pkg/events/eventcodes"
"strings"
)

func ParseSymbols(value string) []any {
var symbols []any
symbolStr := strings.Split(value, ",")
for _, element := range symbolStr {
element = strings.TrimSpace(element)
if element == "all" {
symbols = append(symbols, Osub.NewWildcardSymbol())
} else {
symbols = append(symbols, element)
}
value = strings.TrimSpace(value)

if value == "all" {
return []any{Osub.WildcardSymbol{}}
}
return symbols
values, _ := native.ParseSymbols(value)
return values
}

func ParseEventTypes(value string) []eventcodes.EventCode {
Expand Down

0 comments on commit 5ae927c

Please sign in to comment.