feat: migrate from msgpack to protobuf (handler-base v1.0.0)
Some checks failed
CI / Test (push) Successful in 3m0s
CI / Lint (push) Successful in 2m59s
CI / Release (push) Successful in 1m27s
CI / Docker Build & Push (push) Failing after 7m31s
CI / Notify (push) Successful in 2s

- Replace msgpack.Marshal with proto.Marshal
- Update field names to proto convention (SessionId, SpeakerId)
- Cast Sequence to int32 for proto compatibility
This commit is contained in:
2026-02-21 15:30:43 -05:00
parent a5b66c09c3
commit 0df27901c9
3 changed files with 16 additions and 22 deletions

24
main.go
View File

@@ -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)