Skip to content

Commit

Permalink
proto: Add helper function to marshal Message
Browse files Browse the repository at this point in the history
It will be useful for `interface { Marshal() []byte }` implementations.

Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Dec 16, 2024
1 parent e131cda commit c1bde22
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/proto/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ type Message interface {
MarshalStable(b []byte)
}

// MarshalMessage returns m encoded to dynamically allocated buffer.
func MarshalMessage(m Message) []byte {
b := make([]byte, m.MarshaledSize())
m.MarshalStable(b)
return b
}

// Bytes is a type parameter constraint for any byte arrays.
type Bytes interface{ ~[]byte | ~string }

Expand Down

0 comments on commit c1bde22

Please sign in to comment.