[fidl][go] Handling of nil payloads
With the migration to the new Go bindings, we will stop emitting request
and responses if they have no arguments: this was mistakenly handled as
'messages with size 0' by the encoding, despite the fact that no FIDL
message can have a 0 size.
Instead, the correct approach is to conditionally invoke
encoding/decoding depending on whether a payload should be written.
Change-Id: I487d65a7dd74111b9dee86c9b37a58e7a83659e6
diff --git a/src/syscall/zx/fidl/message.go b/src/syscall/zx/fidl/message.go
index bdbdf2b..f4f16c0 100644
--- a/src/syscall/zx/fidl/message.go
+++ b/src/syscall/zx/fidl/message.go
@@ -54,6 +54,9 @@
// that is, header and payload.
func MarshalMessage(header *MessageHeader, s Payload, data []byte, handles []zx.Handle) (int, int, error) {
MarshalHeader(header, data[:MessageHeaderSize])
+ if s == nil {
+ return MessageHeaderSize, 0, nil
+ }
// TODO(pascallouis): switch to MarshalNew when ready.
nb, nh, err := Marshal(s, data[MessageHeaderSize:], handles[:])
return nb + MessageHeaderSize, nh, err
@@ -65,6 +68,9 @@
if err := UnmarshalHeader(data[:MessageHeaderSize], header); err != nil {
return err
}
+ if s == nil {
+ return nil
+ }
// TODO(pascallouis): switch to MarshalNew when ready.
return Unmarshal(data[MessageHeaderSize:], handles[:], s)
}