[fidl][go] Remove v1 migration conditionals
This CL removes all uses of the flags in MarshalerContext, which were
used to coordinate the old->v1 wire format migration. It leaves the
field definitions for soft transition with fuchsia.git. A follow-up CL
will remove the fields, making MarshalerContext an empty struct.
Test: fx test fidl_go_conformance
Change-Id: I294f2ac76acb9b1058d3b3d564fb9bb541124301
Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/go/+/391333
Reviewed-by: Felix Zhu <fcz@google.com>
Commit-Queue: Mitchell Kember <mkember@google.com>
diff --git a/src/syscall/zx/fidl/ctx_and_header.go b/src/syscall/zx/fidl/ctx_and_header.go
index 5764028..ee30529 100644
--- a/src/syscall/zx/fidl/ctx_and_header.go
+++ b/src/syscall/zx/fidl/ctx_and_header.go
@@ -9,14 +9,16 @@
const FidlWireFormatMagicNumberInitial = 1
type MarshalerContext struct {
+ // TODO(mkember): Remove these fields, making it an empty struct. These
+ // are only kept for a soft transition with fuchsia.git.
DecodeUnionsFromXUnionBytes bool
EncodeUnionsAsXUnionBytes bool
}
+// newCtx returns the default context.
+// During migrations, this controls the default write path.
func newCtx() MarshalerContext {
- return MarshalerContext{
- EncodeUnionsAsXUnionBytes: true,
- }
+ return MarshalerContext{}
}
// MessageHeader represents a transactional message header.
@@ -32,24 +34,10 @@
return msg.Magic == FidlWireFormatMagicNumberInitial
}
-func (msg *MessageHeader) HasUnionFromXunionBytes() bool {
- return msg.Flags[0]&0x01 != 0
-}
-
-func (msg *MessageHeader) SetUnionFromXunionBytes() {
- msg.Flags[0] |= 0x01
-}
-
-func (msg *MessageHeader) UnsetUnionFromXunionBytes() {
- msg.Flags[0] &= ^(uint8(0x01))
-}
-
-// NewCtx creates a new MarshalerContext for unmarshaling based on the flags in
-// the MessageHeader
+// NewCtx creates a new MarshalerContext for unmarshaling based on msg.Flags.
+// During migrations, this controls dynamic behavior in the read path.
func (msg *MessageHeader) NewCtx() MarshalerContext {
- ctx := newCtx()
- ctx.DecodeUnionsFromXUnionBytes = msg.HasUnionFromXunionBytes()
- return ctx
+ return newCtx()
}
var mMessageHeader = MustCreateMarshaler(MessageHeader{})
@@ -68,10 +56,5 @@
Flags: [3]uint8{0, 0, 0},
Magic: FidlWireFormatMagicNumberInitial,
}
- if ctx.EncodeUnionsAsXUnionBytes {
- header.SetUnionFromXunionBytes()
- } else {
- header.UnsetUnionFromXunionBytes()
- }
return header
}
diff --git a/src/syscall/zx/fidl/encoding_new.go b/src/syscall/zx/fidl/encoding_new.go
index 244c944..fcef5f3 100644
--- a/src/syscall/zx/fidl/encoding_new.go
+++ b/src/syscall/zx/fidl/encoding_new.go
@@ -1280,33 +1280,19 @@
}
func (m mOptUnion) getMarshalSize(ctx MarshalerContext) int {
- if ctx.EncodeUnionsAsXUnionBytes {
- return 24
- }
- return 8
+ return 24
}
func (m mOptUnion) getUnmarshalSize(ctx MarshalerContext) int {
- if ctx.DecodeUnionsFromXUnionBytes {
- return 24
- }
- return 8
+ return 24
}
func (m mOptUnion) marshal(ctx MarshalerContext, v reflect.Value, out *encoder) error {
- if ctx.EncodeUnionsAsXUnionBytes {
- return m.mOptXUnion.marshal(ctx, v, out)
- } else {
- return m.mPointer.marshal(ctx, v, out)
- }
+ return m.mOptXUnion.marshal(ctx, v, out)
}
func (m mOptUnion) unmarshal(ctx MarshalerContext, in *decoder, v reflect.Value) error {
- if ctx.DecodeUnionsFromXUnionBytes {
- return m.mOptXUnion.unmarshal(ctx, in, v)
- } else {
- return m.mPointer.unmarshal(ctx, in, v)
- }
+ return m.mOptXUnion.unmarshal(ctx, in, v)
}
type mArray struct {