-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
42 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,13 @@ import ( | |
"csgo-2d-demo-player/pkg/message" | ||
"csgo-2d-demo-player/pkg/parser" | ||
"fmt" | ||
"io" | ||
"log" | ||
"syscall/js" | ||
Check failure on line 11 in cmd/wasm/wasm.go GitHub Actions / lint
|
||
"time" | ||
|
||
"github.com/markus-wa/demoinfocs-golang/v5/pkg/demoinfocs" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
func main() { | ||
|
@@ -21,27 +23,42 @@ func main() { | |
} | ||
|
||
func testt(this js.Value, args []js.Value) interface{} { | ||
fmt.Printf("testt: +%v\n", args[0].Get("size")) | ||
input := make([]byte, args[0].Get("size")) | ||
fmt.Printf("testt: +%v\n", args[0].Get("length")) | ||
input := make([]byte, args[0].Get("length").Int()) | ||
js.CopyBytesToGo(input, args[0]) | ||
|
||
fmt.Println("fer") | ||
|
||
gzipReader, streamErr := gzip.NewReader(bytes.NewReader(input)) | ||
parse(bytes.NewReader(input), args[1]) | ||
|
||
return js.ValueOf("2") | ||
} | ||
|
||
func parse(input io.Reader, callback js.Value) { | ||
fmt.Printf("callback? %+v\n", callback) | ||
|
||
gzipReader, streamErr := gzip.NewReader(input) | ||
if streamErr != nil { | ||
log.Printf("Failed to create gzip reader from demo. %+v", streamErr) | ||
} | ||
|
||
startTime := time.Now().Local() | ||
err := parser.Parse(gzipReader, func(msg *message.Message, state demoinfocs.GameState) { | ||
fmt.Printf("message: %+v \n", msg.MsgType) | ||
|
||
payload, protoErr := proto.Marshal(msg) | ||
if protoErr != nil { | ||
fmt.Printf("failed to marshall the message: %+v %+v\n", msg, protoErr) | ||
} | ||
arrayConstructor := js.Global().Get("Uint8Array") | ||
dataJS := arrayConstructor.New(len(payload)) | ||
js.CopyBytesToJS(dataJS, payload) | ||
callback.Invoke(dataJS) | ||
}) | ||
fmt.Printf("parsing took: %s\n", time.Since(startTime)) | ||
|
||
if err != nil { | ||
fmt.Printf("Failed to parse a demo: %+v \n", err) | ||
} | ||
fmt.Println("demo parsed?") | ||
|
||
return js.ValueOf("2") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters