mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
[go-marshal] Support marshalling for structs with names starting with W.
Due to how marshallable interface implementation was generated, we could not marshal a struct whose named started with W because there was a naming collision with parameter (w io.Writer) and type (w *StuctName). Used "writer" as parameter name to avoid collision. PiperOrigin-RevId: 328343930
This commit is contained in:
@@ -400,13 +400,13 @@ func (g *interfaceGenerator) emitMarshallableForStruct(st *ast.StructType) {
|
||||
|
||||
g.emit("// WriteTo implements io.WriterTo.WriteTo.\n")
|
||||
g.recordUsedImport("io")
|
||||
g.emit("func (%s *%s) WriteTo(w io.Writer) (int64, error) {\n", g.r, g.typeName())
|
||||
g.emit("func (%s *%s) WriteTo(writer io.Writer) (int64, error) {\n", g.r, g.typeName())
|
||||
g.inIndent(func() {
|
||||
fallback := func() {
|
||||
g.emit("// Type %s doesn't have a packed layout in memory, fall back to MarshalBytes.\n", g.typeName())
|
||||
g.emit("buf := make([]byte, %s.SizeBytes())\n", g.r)
|
||||
g.emit("%s.MarshalBytes(buf)\n", g.r)
|
||||
g.emit("length, err := w.Write(buf)\n")
|
||||
g.emit("length, err := writer.Write(buf)\n")
|
||||
g.emit("return int64(length), err\n")
|
||||
}
|
||||
if thisPacked {
|
||||
@@ -421,7 +421,7 @@ func (g *interfaceGenerator) emitMarshallableForStruct(st *ast.StructType) {
|
||||
// Fast serialization.
|
||||
g.emitCastToByteSlice(g.r, "buf", fmt.Sprintf("%s.SizeBytes()", g.r))
|
||||
|
||||
g.emit("length, err := w.Write(buf)\n")
|
||||
g.emit("length, err := writer.Write(buf)\n")
|
||||
g.emitKeepAlive(g.r)
|
||||
g.emit("return int64(length), err\n")
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user