Skip to content

Commit

Permalink
fixed dodgy pierrec/lz4 compression
Browse files Browse the repository at this point in the history
  • Loading branch information
dioptre committed Dec 3, 2024
1 parent 3998fa3 commit bad00f4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ toolchain go1.23.3
require (
github.com/ClickHouse/clickhouse-go/v2 v2.30.0
github.com/aws/aws-sdk-go v1.55.5
github.com/bkaradzic/go-lz4 v1.0.0
github.com/cockroachdb/pebble v0.0.0-20230307175142-1c38c4cb89d4
github.com/coreos/pkg v0.0.0-20230209195159-6f3db454fdf8
github.com/gocql/gocql v1.3.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 h1:mXoPYz/Ul5HYEDvkta6I8/rnYM5gSdSV2tJ6XbZuEtY=
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k=
github.com/bkaradzic/go-lz4 v1.0.0 h1:RXc4wYsyz985CkXXeX04y4VnZFGG8Rd43pRaHsOXAKk=
github.com/bkaradzic/go-lz4 v1.0.0/go.mod h1:0YdlkowM3VswSROI7qDxhRvJ3sLhlFrRRwjwegp5jy4=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down
16 changes: 8 additions & 8 deletions tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* This file is licensed under the Apache 2 License. See LICENSE for details.
*
* Copyright (c) 2018 Andrew Grosser. All Rights Reserved.
* Copyright (c) 2018-2024 Andrew Grosser. All Rights Reserved.
*
* `...
* yNMMh`
Expand Down Expand Up @@ -69,15 +69,14 @@ import (
"strings"
"time"

"github.com/aws/aws-sdk-go/service/s3"

"github.com/ClickHouse/clickhouse-go/v2"
"github.com/aws/aws-sdk-go/service/s3"
lz4 "github.com/bkaradzic/go-lz4"
"github.com/gocql/gocql"
"github.com/google/uuid"
"github.com/gorilla/mux"
"github.com/gorilla/websocket"
"github.com/nats-io/nats.go"
"github.com/pierrec/lz4/v4"
"golang.org/x/crypto/acme/autocert"
)

Expand Down Expand Up @@ -833,6 +832,7 @@ func main() {

//////////////////////////////////////// WEBSOCKET
http.HandleFunc("/tr/"+apiVersion+"/ws", func(w http.ResponseWriter, r *http.Request) {
fmt.Println("Websocket request:", r.Method)
if r.Method == http.MethodOptions {
//Lets just allow requests to this endpoint
handlePreflight(&w, &configuration.AllowOrigin)
Expand Down Expand Up @@ -877,15 +877,15 @@ func main() {
continue
}
case websocket.BinaryMessage:
// Decompress LZ4 data
dst := make([]byte, len(msg)*3)
decompressed, err := lz4.UncompressBlock(msg, dst)
// Decompress the message
decompressed, err := lz4.Decode(nil, msg)
if err != nil {
fmt.Printf("Error decompressing message: %v\n", err)
continue
}

// Parse JSON
if err := json.Unmarshal(dst[:decompressed], &data); err != nil {
if err := json.Unmarshal(decompressed, &data); err != nil {
fmt.Printf("Error parsing JSON: %v\n", err)
continue
}
Expand Down

0 comments on commit bad00f4

Please sign in to comment.