[fidl][go] Support for v2 tables

The Go FIDL bindings currently support the new envelope format inside
of unions, but not in tables. This CL adds the missing table support.

The GIDL tests specified in the following CL pass on this change:
Ib06a953bc251c18600727875a8c0bedf447bc811

Bug: 80348
Change-Id: Iee8956a9fd9a4aed42e21cc847490c010c636bcb
Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/go/+/557621
Commit-Queue: Benjamin Prosnitz <bprosnitz@google.com>
Reviewed-by: Mitchell Kember <mkember@google.com>
diff --git a/src/syscall/zx/fidl/encoding_new.go b/src/syscall/zx/fidl/encoding_new.go
index 0eae4d6..5e84f32 100644
--- a/src/syscall/zx/fidl/encoding_new.go
+++ b/src/syscall/zx/fidl/encoding_new.go
@@ -1244,7 +1244,12 @@
 	return m.size
 }
 
-const envelopeSize = 16
+func envelopeSize(ctx MarshalerContext) int {
+	if ctx.UseV2WireFormat {
+		return 8
+	}
+	return 16
+}
 
 type envelopeHeader struct {
 	byteValue   []byte
@@ -1396,14 +1401,16 @@
 		in.handleInfos = usedHandles
 	}
 
+	if header.isInline {
+		unknownData := in.buffer[offset:][:4]
+		return unknownData, unknownHandles, nil
+	}
+
 	start, err := in.newObject(int(header.byteCount), depth)
 	if err != nil {
 		return nil, nil, err
 	}
 
-	if err != nil {
-		return nil, nil, err
-	}
 	unknownData := in.buffer[start:][:header.byteCount]
 
 	return unknownData, unknownHandles, nil
@@ -1442,6 +1449,7 @@
 	return true, nil
 }
 
+// TODO(fxbug.dev/81180) Validate inline size <= 4 if header has inline bit set.
 func unmarshalEnvelope(ctx MarshalerContext, m Marshaler, in *decoder, offset int, depth int, v unsafevalue.Value, mode unmarshalEnvelopeMode) (bool, error) {
 	startingFrom := in.nextObject
 	unclaimedHandles := uint32(len(in.handleInfos))
@@ -1534,7 +1542,7 @@
 	}
 
 	// Encode in the out-of-line object.
-	outOfLineOffset, err := out.newObject(int(maxOrdinal)*envelopeSize, depth)
+	outOfLineOffset, err := out.newObject(int(maxOrdinal)*envelopeSize(ctx), depth)
 	if err != nil {
 		return err
 	}
@@ -1612,7 +1620,7 @@
 		index              = 0
 		unknownData map[uint64]UnknownData
 	)
-	outOfLineOffset, err := in.newObject(int(maxOrdinal)*envelopeSize, depth)
+	outOfLineOffset, err := in.newObject(int(maxOrdinal)*envelopeSize(ctx), depth)
 	if err != nil {
 		return err
 	}
@@ -1643,7 +1651,7 @@
 			}
 		}
 		ordinal++
-		envelopeOffset += 16
+		envelopeOffset += envelopeSize(ctx)
 		if fieldKnown {
 			index++
 		}