Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Unified Diff: mojom/generators/go/translator/mojom_file.go

Issue 2061243002: Encode and decode fields of union type. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojom/generators/go/templates/encoding_test.go ('k') | mojom/generators/go/translator/translator.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojom/generators/go/translator/mojom_file.go
diff --git a/mojom/generators/go/translator/mojom_file.go b/mojom/generators/go/translator/mojom_file.go
index 8fced7fce6148d362f8ee15cbfbc48a43deac8c7..db10e4af0c51623e9582aacac8b2ff061435e3a4 100644
--- a/mojom/generators/go/translator/mojom_file.go
+++ b/mojom/generators/go/translator/mojom_file.go
@@ -111,6 +111,9 @@ type EncodingInfo interface {
// IsStruct returns true if the field is a struct.
IsStruct() bool
+ // IsUnion returns true if the field is a union.
+ IsUnion() bool
+
// IsArray returns true if the field is an array.
IsArray() bool
@@ -183,6 +186,10 @@ func (b *baseEncodingInfo) IsStruct() bool {
return false
}
+func (b *baseEncodingInfo) IsUnion() bool {
+ return false
+}
+
func (b *baseEncodingInfo) IsArray() bool {
return false
}
@@ -388,3 +395,43 @@ func (t *structTypeEncodingInfo) WriteFunction() string {
func (t *structTypeEncodingInfo) ReadFunction() string {
panic("Structs don't have a read function.")
}
+
+////////////////////////////////////////////////////////////////////////////////
+
+// unionTypeEncodingInfo is the EncodingInfo for a union.
+type unionTypeEncodingInfo struct {
+ baseEncodingInfo
+ nestedUnion bool
+ nullable bool
+}
+
+func (t *unionTypeEncodingInfo) BitSize() uint32 {
+ if t.nestedUnion {
+ return uint32(64)
+ }
+ return uint32(128)
+}
+
+func (t *unionTypeEncodingInfo) IsUnion() bool {
+ return true
+}
+
+func (t *unionTypeEncodingInfo) IsPointer() bool {
+ return t.nestedUnion
+}
+
+func (b *unionTypeEncodingInfo) IsNullable() bool {
+ return b.nullable
+}
+
+func (b *unionTypeEncodingInfo) setNullable(nullable bool) {
+ b.nullable = nullable
+}
+
+func (t *unionTypeEncodingInfo) WriteFunction() string {
+ panic("Unions don't have a write function.")
+}
+
+func (t *unionTypeEncodingInfo) ReadFunction() string {
+ panic("Unions don't have a read function.")
+}
« no previous file with comments | « mojom/generators/go/templates/encoding_test.go ('k') | mojom/generators/go/translator/translator.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698