Index: third_party/mojo/src/mojo/public/go/bindings/encoder.go |
diff --git a/third_party/mojo/src/mojo/public/go/bindings/encoder.go b/third_party/mojo/src/mojo/public/go/bindings/encoder.go |
index 822aaa477d4eac32ebff104bd0fba2187ef2d2ad..918c883f9d23bf4a9434639761a0f4bc9b9211b6 100644 |
--- a/third_party/mojo/src/mojo/public/go/bindings/encoder.go |
+++ b/third_party/mojo/src/mojo/public/go/bindings/encoder.go |
@@ -163,6 +163,12 @@ func (e *Encoder) StartStruct(size, version uint32) { |
e.pushState(header, 0) |
} |
+// StartUnion starts encoding a union and writes its data header. |
+func (e *Encoder) StartUnion(tag uint32) { |
+ header := DataHeader{uint32(16), tag} |
+ e.pushState(header, 0) |
+} |
+ |
func (e *Encoder) writeDataHeader(header DataHeader) { |
binary.LittleEndian.PutUint32(e.buf[e.state().offset:], header.Size) |
binary.LittleEndian.PutUint32(e.buf[e.state().offset+4:], header.ElementsOrVersion) |
@@ -285,6 +291,22 @@ func (e *Encoder) WriteFloat64(value float64) error { |
return e.WriteUint64(math.Float64bits(value)) |
} |
+// WriteNullUnion writes a null union. |
+func (e *Encoder) WriteNullUnion() error { |
+ if err := ensureElementBitSizeAndCapacity(e.state(), 128); err != nil { |
+ return err |
+ } |
+ e.state().alignOffsetToBytes() |
+ e.state().offset = align(e.state().offset, 16) |
+ binary.LittleEndian.PutUint64(e.buf[e.state().offset:], 0) |
+ e.state().skipBytes(8) |
+ binary.LittleEndian.PutUint64(e.buf[e.state().offset:], 0) |
+ e.state().skipBytes(8) |
+ e.state().elementsProcessed++ |
+ |
+ return nil |
+} |
+ |
// WriteNullPointer writes a null pointer. |
func (e *Encoder) WriteNullPointer() error { |
return e.WriteUint64(0) |