diff options
Diffstat (limited to 'nexgb/xgbgen/go_struct.go')
-rw-r--r-- | nexgb/xgbgen/go_struct.go | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/nexgb/xgbgen/go_struct.go b/nexgb/xgbgen/go_struct.go index 6925c88..600ebaf 100644 --- a/nexgb/xgbgen/go_struct.go +++ b/nexgb/xgbgen/go_struct.go @@ -13,7 +13,7 @@ func (s *Struct) Define(c *Context) { // Write function that reads bytes and produces this struct. s.Read(c) - // Write function that reads a list of this structs. + // Write function that reads bytes and produces a list of this struct. s.ReadList(c) // Write function that writes bytes given this struct. @@ -68,7 +68,7 @@ func (s *Struct) ReadList(c *Context) { func (s *Struct) Write(c *Context) { c.Putln("// Struct write %s", s.SrcName()) c.Putln("func (v %s) Bytes() []byte {", s.SrcName()) - c.Putln("buf := make([]byte, %s)", s.Size().Reduce("s.", "")) + c.Putln("buf := make([]byte, %s)", s.Size().Reduce("v.", "")) c.Putln("b := 0") c.Putln("") for _, field := range s.Fields { @@ -88,10 +88,11 @@ func (s *Struct) WriteList(c *Context) { c.Putln("for _, item := range list {") c.Putln("structBytes = item.Bytes()") c.Putln("copy(buf[b:], len(structBytes))") - c.Putln("b += len(structBytes)") + c.Putln("b += pad(len(structBytes))") c.Putln("}") c.Putln("return b") c.Putln("}") + c.Putln("") } func (s *Struct) WriteListSize(c *Context) { @@ -101,7 +102,7 @@ func (s *Struct) WriteListSize(c *Context) { c.Putln("for _, item := range list {") c.Putln("size += %s", s.Size().Reduce("item.", "")) c.Putln("}") - c.Putln("return pad(size)") + c.Putln("return size") c.Putln("}") c.Putln("") } |