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 3m1s
CI / Release (push) Successful in 1m17s
CI / Docker Build & Push (push) Failing after 7m26s
CI / Notify (push) Successful in 1s

- Replace msgpack encoding with protobuf wire format
- Update field names to proto convention (SessionId)
- Cast int fields to int32 (ChunkIndex, TotalChunks, SampleRate, Count)
- Use pointer slices for repeated messages ([]*TTSVoiceInfo)
- Rewrite tests for proto round-trips
This commit is contained in:
2026-02-21 15:30:51 -05:00
parent 147c60fd64
commit 238bf47844
5 changed files with 42 additions and 48 deletions

View File

@@ -11,7 +11,7 @@ import (
"git.daviestechlabs.io/daviestechlabs/handler-base/messages"
"git.daviestechlabs.io/daviestechlabs/handler-base/natsutil"
"github.com/vmihailenco/msgpack/v5"
"google.golang.org/protobuf/proto"
)
func TestVoiceRegistryRefresh(t *testing.T) {
@@ -105,18 +105,18 @@ func TestSynthesizeHTTP(t *testing.T) {
}
func TestTTSRequestDecode(t *testing.T) {
req := messages.TTSRequest{
req := &messages.TTSRequest{
Text: "hello world",
Speaker: "custom-en",
Language: "en",
Stream: true,
}
data, err := msgpack.Marshal(&req)
data, err := proto.Marshal(req)
if err != nil {
t.Fatal(err)
}
decoded, err := natsutil.Decode[messages.TTSRequest](data)
if err != nil {
var decoded messages.TTSRequest
if err := natsutil.Decode(data, &decoded); err != nil {
t.Fatal(err)
}
if decoded.Text != "hello world" {
@@ -132,7 +132,7 @@ func TestTTSRequestDecode(t *testing.T) {
func TestTTSAudioChunkRoundtrip(t *testing.T) {
chunk := messages.TTSAudioChunk{
SessionID: "sess-001",
SessionId: "sess-001",
ChunkIndex: 0,
TotalChunks: 2,
Audio: make([]byte, 32768),
@@ -140,16 +140,16 @@ func TestTTSAudioChunkRoundtrip(t *testing.T) {
Timestamp: 1234567890,
SampleRate: 24000,
}
data, err := msgpack.Marshal(&chunk)
data, err := proto.Marshal(&chunk)
if err != nil {
t.Fatal(err)
}
var got messages.TTSAudioChunk
if err := msgpack.Unmarshal(data, &got); err != nil {
if err := proto.Unmarshal(data, &got); err != nil {
t.Fatal(err)
}
if got.SessionID != "sess-001" {
t.Errorf("SessionID = %q", got.SessionID)
if got.SessionId != "sess-001" {
t.Errorf("SessionID = %q", got.SessionId)
}
if len(got.Audio) != 32768 {
t.Errorf("Audio len = %d", len(got.Audio))