summaryrefslogtreecommitdiffhomepage
path: root/tools/go_marshal/README.md
diff options
context:
space:
mode:
authorAyush Ranjan <ayushranjan@google.com>2021-02-08 18:03:29 -0800
committergVisor bot <gvisor-bot@google.com>2021-02-08 18:08:29 -0800
commitcfa4633c3d206aa2f9abdaac60d053162244ee6d (patch)
treecddf8d20bde9b55bee4d510876b77af92dc635a3 /tools/go_marshal/README.md
parente51f775cbb8db89d1dac6dcf584be5eef1f82d3c (diff)
[go-marshal] Add dynamic tag in go_marshal.
This makes it easier to implement dynamically sized types in go-marshal. You really only need to implement MarshalBytes, UnmarshalBytes and SizeBytes to implement the entire interface. By using the `dynamic` tag, the autogenerator will generate the rest of the methods for us. This change also simplifies how KernelIPTGetEntries implements Marshallable using the newly added utility. PiperOrigin-RevId: 356397114
Diffstat (limited to 'tools/go_marshal/README.md')
-rw-r--r--tools/go_marshal/README.md12
1 files changed, 12 insertions, 0 deletions
diff --git a/tools/go_marshal/README.md b/tools/go_marshal/README.md
index d8045c295..eddba0c21 100644
--- a/tools/go_marshal/README.md
+++ b/tools/go_marshal/README.md
@@ -98,6 +98,18 @@ for embedded structs that are not aligned.
Because of this, it's generally best to avoid using `marshal:"unaligned"` and
insert explicit padding fields instead.
+## Working with dynamically sized structs
+
+While `go_marshal` seamlessly supports statically sized structs (which most ABI
+structs are), it can also used for other uses cases where marshalling is
+required. There is some provision to partially support dynamically sized structs
+that may not be ABI structs. A user can define a dynamic struct and define
+`SizeBytes()`, `MarshalBytes(dst)` and `UnmarshalBytes(src)` for it. Then user
+can then add a comment above the struct like `// +marshal dynamic` while will
+make `go_marshal` autogenerate the remaining methods required to complete the
+`Marshallable` interface. This feature is currently only available for structs
+and can not be used alongside the Slice API.
+
## Modifying the `go_marshal` Tool
The following are some guidelines for modifying the `go_marshal` tool: