From c0bd71c5a596af6cf7f05a712232464623da0ba9 Mon Sep 17 00:00:00 2001 From: Ayush Ranjan <ayushranjan@google.com> Date: Mon, 22 Mar 2021 19:15:48 -0700 Subject: [lisa] Support dynamic types for all types. We were only supporting dynamic struct types. With this change, users can make any type dynamic. The tool (correctly) blindly just generates the remaining methods needed to implement Marshallable using the 3 methods defined by the user on the dynamic type. This is helpful in situations like: type StringArray []string Added a test for such a use case. PiperOrigin-RevId: 364463164 --- tools/go_marshal/test/test.go | 35 ----------------------------------- 1 file changed, 35 deletions(-) (limited to 'tools/go_marshal/test/test.go') diff --git a/tools/go_marshal/test/test.go b/tools/go_marshal/test/test.go index b8eb989d9..e7e3ed74a 100644 --- a/tools/go_marshal/test/test.go +++ b/tools/go_marshal/test/test.go @@ -16,8 +16,6 @@ package test import ( - "gvisor.dev/gvisor/pkg/marshal/primitive" - // We're intentionally using a package name alias here even though it's not // necessary to test the code generator's ability to handle package aliases. ex "gvisor.dev/gvisor/tools/go_marshal/test/external" @@ -200,36 +198,3 @@ type Type11 struct { ex.External y int64 } - -// Type12Dynamic is a dynamically sized struct which depends on the autogenerator -// to generate some Marshallable methods for it. -// -// +marshal dynamic -type Type12Dynamic struct { - X primitive.Int64 - Y []primitive.Int64 -} - -// SizeBytes implements marshal.Marshallable.SizeBytes. -func (t *Type12Dynamic) SizeBytes() int { - return (len(t.Y) * 8) + t.X.SizeBytes() -} - -// MarshalBytes implements marshal.Marshallable.MarshalBytes. -func (t *Type12Dynamic) MarshalBytes(dst []byte) { - t.X.MarshalBytes(dst) - dst = dst[t.X.SizeBytes():] - for i, x := range t.Y { - x.MarshalBytes(dst[i*8 : (i+1)*8]) - } -} - -// UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes. -func (t *Type12Dynamic) UnmarshalBytes(src []byte) { - t.X.UnmarshalBytes(src) - for i := t.X.SizeBytes(); i < len(src); i += 8 { - var x primitive.Int64 - x.UnmarshalBytes(src[i:]) - t.Y = append(t.Y, x) - } -} -- cgit v1.2.3