From 5cc0bbbafb2dc7d248bc3141b4cfa022d420abd1 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Sat, 15 Feb 2020 00:00:04 -0800 Subject: Ensure Marshallable.SizeBytes() always works on a typed nil pointer. This lets go-marshal replace various calls to binary.Size() throughout the sentry without requiring concrete objects. PiperOrigin-RevId: 295299965 --- tools/go_marshal/marshal/marshal.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tools/go_marshal/marshal') diff --git a/tools/go_marshal/marshal/marshal.go b/tools/go_marshal/marshal/marshal.go index e521b50bd..20353850d 100644 --- a/tools/go_marshal/marshal/marshal.go +++ b/tools/go_marshal/marshal/marshal.go @@ -48,6 +48,10 @@ type Marshallable interface { // SizeBytes is the size of the memory representation of a type in // marshalled form. + // + // SizeBytes must handle a nil receiver. Practically, this means SizeBytes + // cannot deference any fields on the object implementing it (but will + // likely make use of the type of these fields). SizeBytes() int // MarshalBytes serializes a copy of a type to dst. dst must be at least -- cgit v1.2.3