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 3m0s
CI / Release (push) Successful in 59s
CI / Notify (push) Successful in 2s
CI / Docker Build & Push (push) Failing after 8m4s

- Replace msgpack encoding with protobuf wire format
- Update field names to proto convention
- Use pointer slices for repeated message fields ([]*DocumentSource)
- Rewrite tests for proto round-trips
This commit is contained in:
2026-02-21 15:30:26 -05:00
parent d891140817
commit 6e498cc0d5
4 changed files with 27 additions and 32 deletions

View File

@@ -5,26 +5,26 @@ 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 TestVoiceRequestDecode(t *testing.T) {
req := messages.VoiceRequest{
RequestID: "req-123",
req := &messages.VoiceRequest{
RequestId: "req-123",
Audio: []byte{0x01, 0x02, 0x03},
Language: "en",
Collection: "docs",
}
data, err := msgpack.Marshal(&req)
data, err := proto.Marshal(req)
if err != nil {
t.Fatal(err)
}
decoded, err := natsutil.Decode[messages.VoiceRequest](data)
if err != nil {
var decoded messages.VoiceRequest
if err := natsutil.Decode(data, &decoded); err != nil {
t.Fatal(err)
}
if decoded.RequestID != "req-123" {
t.Errorf("RequestID = %q", decoded.RequestID)
if decoded.RequestId != "req-123" {
t.Errorf("RequestId = %q", decoded.RequestId)
}
if len(decoded.Audio) != 3 {
t.Errorf("Audio len = %d", len(decoded.Audio))
@@ -32,19 +32,19 @@ func TestVoiceRequestDecode(t *testing.T) {
}
func TestVoiceResponseRoundtrip(t *testing.T) {
resp := messages.VoiceResponse{
RequestID: "req-456",
resp := &messages.VoiceResponse{
RequestId: "req-456",
Response: "It is sunny today.",
Audio: make([]byte, 8000),
Transcription: "What is the weather?",
Sources: []messages.DocumentSource{{Text: "weather doc", Score: 0.9}},
Sources: []*messages.DocumentSource{{Text: "weather doc", Score: 0.9}},
}
data, err := msgpack.Marshal(&resp)
data, err := proto.Marshal(resp)
if err != nil {
t.Fatal(err)
}
var got messages.VoiceResponse
if err := msgpack.Unmarshal(data, &got); err != nil {
if err := proto.Unmarshal(data, &got); err != nil {
t.Fatal(err)
}
if got.Response != "It is sunny today." {