From 33bc0ca43cee3635c35520d9ddc90831b6554746 Mon Sep 17 00:00:00 2001 From: Bradley Kemp Date: Tue, 30 Jun 2020 14:21:40 +0100 Subject: [PATCH] Fix marshalling of raw_message field for empty messages (#106) * Fix marshalling of raw_message field for empty messages * Add changelog entry * Fix null vs "" marshalling --- CHANGELOG.md | 3 +++ grpc-dump/dump/recorded_server_stream.go | 4 ++++ internal/dump.go | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d2bb58..6d85d6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## Unreleased +* Fixed a bug that prevented replaying empty gRPC messages [#105](https://github.com/bradleyjkemp/grpc-tools/pull/105). + ## [v0.2.5](https://github.com/bradleyjkemp/grpc-tools/releases/tag/v0.2.5) * Added grpc-proxy options `WithServerOptions` and `WithDialOptions`, deprecated `WithOptions` [#71](https://github.com/bradleyjkemp/grpc-tools/pull/71). * Added a new command-line option, `--interface` to allow choosing which network interface `grpc-proxy` listens on [#81](https://github.com/bradleyjkemp/grpc-tools/pull/81). diff --git a/grpc-dump/dump/recorded_server_stream.go b/grpc-dump/dump/recorded_server_stream.go index 3cef2bf..a8004b7 100644 --- a/grpc-dump/dump/recorded_server_stream.go +++ b/grpc-dump/dump/recorded_server_stream.go @@ -42,6 +42,10 @@ func (ss *recordedServerStream) SetTrailer(trailers metadata.MD) { func (ss *recordedServerStream) SendMsg(m interface{}) error { message := m.([]byte) + if message == nil { + // although the message is nil here, we actually want to save it as the empty message ("") + message = []byte{} + } ss.Lock() ss.events = append(ss.events, &internal.Message{ MessageOrigin: internal.ServerMessage, diff --git a/internal/dump.go b/internal/dump.go index 52ce330..b38cf9c 100644 --- a/internal/dump.go +++ b/internal/dump.go @@ -35,7 +35,7 @@ const ( type Message struct { MessageOrigin MessageOrigin `json:"message_origin,omitempty"` - RawMessage []byte `json:"raw_message,omitempty"` + RawMessage []byte `json:"raw_message"` Message interface{} `json:"message,omitempty"` Timestamp time.Time `json:"timestamp"` }