From 0df27901c95ee380dcbd193c17833f3cf951e014 Mon Sep 17 00:00:00 2001 From: "Billy D." Date: Sat, 21 Feb 2026 15:30:43 -0500 Subject: [PATCH] feat: migrate from msgpack to protobuf (handler-base v1.0.0) - Replace msgpack.Marshal with proto.Marshal - Update field names to proto convention (SessionId, SpeakerId) - Cast Sequence to int32 for proto compatibility --- go.mod | 6 ++---- go.sum | 8 ++------ main.go | 24 ++++++++++++------------ 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index 53c727c..5803f49 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module git.daviestechlabs.io/daviestechlabs/stt-module go 1.25.1 require ( - git.daviestechlabs.io/daviestechlabs/handler-base v0.1.5 + git.daviestechlabs.io/daviestechlabs/handler-base v1.0.0 github.com/nats-io/nats.go v1.48.0 - github.com/vmihailenco/msgpack/v5 v5.4.1 + google.golang.org/protobuf v1.36.11 ) require ( @@ -19,7 +19,6 @@ require ( github.com/klauspost/compress v1.18.0 // indirect github.com/nats-io/nkeys v0.4.11 // indirect github.com/nats-io/nuid v1.0.1 // indirect - github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect go.opentelemetry.io/auto/sdk v1.2.1 // indirect go.opentelemetry.io/otel v1.40.0 // indirect go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.40.0 // indirect @@ -37,5 +36,4 @@ require ( google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409 // indirect google.golang.org/grpc v1.78.0 // indirect - google.golang.org/protobuf v1.36.11 // indirect ) diff --git a/go.sum b/go.sum index efceef0..5d7dfc1 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -git.daviestechlabs.io/daviestechlabs/handler-base v0.1.5 h1:DqYZpeluTXh5QKqdVFgN8YIMh4Ycqzw5E9+5FTNDFCA= -git.daviestechlabs.io/daviestechlabs/handler-base v0.1.5/go.mod h1:M3HgvUDWnRn7cX3BE8l+HvoCUYtmRr5OoumB+hnRHoE= +git.daviestechlabs.io/daviestechlabs/handler-base v1.0.0 h1:pB3ehOKaDYQfbyRBKQXrB9curqSFteLrDveoElRKnBY= +git.daviestechlabs.io/daviestechlabs/handler-base v1.0.0/go.mod h1:zocOHFt8yY3cW4+Xi37sNr5Tw7KcjGFSZqgWYxPWyqA= github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM= github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -33,10 +33,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= -github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8= -github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok= -github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= -github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/otel v1.40.0 h1:oA5YeOcpRTXq6NN7frwmwFR0Cn3RhTVZvXsP4duvCms= diff --git a/main.go b/main.go index d29f228..f7028a1 100644 --- a/main.go +++ b/main.go @@ -20,7 +20,7 @@ import ( "time" "github.com/nats-io/nats.go" - "github.com/vmihailenco/msgpack/v5" + "google.golang.org/protobuf/proto" "git.daviestechlabs.io/daviestechlabs/handler-base/config" "git.daviestechlabs.io/daviestechlabs/handler-base/health" @@ -324,17 +324,17 @@ func main() { if transcript != "" { result := &messages.STTTranscription{ - SessionID: sessionID, + SessionId: sessionID, Transcript: transcript, - Sequence: seq, + Sequence: int32(seq), IsPartial: !complete, IsFinal: complete, Timestamp: time.Now().Unix(), - SpeakerID: speakerID, + SpeakerId: speakerID, HasVoiceActivity: hasVoice, State: state, } - packed, _ := msgpack.Marshal(result) + packed, _ := proto.Marshal(result) _ = nc.Conn().Publish(fmt.Sprintf("%s.%s", transcriptionSubjectPrefix, sessionID), packed) slog.Info("published transcription", "session", sessionID, "seq", seq) } @@ -378,8 +378,8 @@ func main() { } sessionID := parts[3] - streamMsg, err := natsutil.Decode[messages.STTStreamMessage](natMsg.Data) - if err != nil { + var streamMsg messages.STTStreamMessage + if err := natsutil.Decode(natMsg.Data, &streamMsg); err != nil { slog.Error("decode error", "error", err) return } @@ -391,8 +391,8 @@ func main() { if streamMsg.State != "" { buf.setState(streamMsg.State) } - if streamMsg.SpeakerID != "" { - buf.speakerID = streamMsg.SpeakerID + if streamMsg.SpeakerId != "" { + buf.speakerID = streamMsg.SpeakerId } sessionsMu.Lock() sessions[sessionID] = buf @@ -442,12 +442,12 @@ func main() { // Check for interrupt if buffer.checkInterrupt(streamMsg.Audio, enableInterrupt, audioLevelThreshold, interruptDuration) { interruptMsg := &messages.STTInterrupt{ - SessionID: sessionID, + SessionId: sessionID, Type: "interrupt", Timestamp: time.Now().Unix(), - SpeakerID: buffer.speakerID, + SpeakerId: buffer.speakerID, } - packed, _ := msgpack.Marshal(interruptMsg) + packed, _ := proto.Marshal(interruptMsg) _ = nc.Conn().Publish(fmt.Sprintf("%s.%s", transcriptionSubjectPrefix, sessionID), packed) slog.Info("published interrupt", "session", sessionID) buffer.setState(stateListening)