blob: ee30529503a6580ebb3e6d7ab7751d3ee23faa48 [file] [log] [blame]
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build fuchsia
package fidl
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{}
}
// MessageHeader represents a transactional message header.
type MessageHeader struct {
_ struct{} `fidl:"s" fidl_size_v1:"16" fidl_alignment_v1:"8"`
Txid uint32 `fidl:"0" fidl_offset_v1:"0" fidl_bounds:""`
Flags [3]uint8 `fidl:"4" fidl_offset_v1:"4" fidl_bounds:""`
Magic uint8 `fidl:"7" fidl_offset_v1:"7" fidl_bounds:""`
Ordinal uint64 `fidl:"8" fidl_offset_v1:"8" fidl_bounds:""`
}
func (msg *MessageHeader) IsSupportedVersion() bool {
return msg.Magic == FidlWireFormatMagicNumberInitial
}
// 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 {
return newCtx()
}
var mMessageHeader = MustCreateMarshaler(MessageHeader{})
var MessageHeaderSize = 16
func (msg *MessageHeader) Marshaler() Marshaler {
return mMessageHeader
}
// NewHeader create a new MessageHeader for marshaling with the correct flags
// set based on the MarshalerContext. It is the caller's responsibilty to set
// the transaction ID and method ordinal
func (ctx MarshalerContext) NewHeader() MessageHeader {
header := MessageHeader{
Flags: [3]uint8{0, 0, 0},
Magic: FidlWireFormatMagicNumberInitial,
}
return header
}