summaryrefslogtreecommitdiffhomepage
path: root/tools/go_marshal/marshal
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2020-02-15 00:00:04 -0800
committergVisor bot <gvisor-bot@google.com>2020-02-15 00:01:02 -0800
commit5cc0bbbafb2dc7d248bc3141b4cfa022d420abd1 (patch)
treee5ad432e378c86d259d7e2faba862839cce7ecc9 /tools/go_marshal/marshal
parent3d32ad1367b4e84a0822808f44bd7b9f9351db71 (diff)
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
Diffstat (limited to 'tools/go_marshal/marshal')
-rw-r--r--tools/go_marshal/marshal/marshal.go4
1 files changed, 4 insertions, 0 deletions
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