feat: migrate from msgpack to protobuf (handler-base v1.0.0)
- 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:
20
main_test.go
20
main_test.go
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user