aboutsummaryrefslogtreecommitdiff
path: root/nexgb/xgbgen/go_struct.go
diff options
context:
space:
mode:
authorAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-05-01 01:08:03 -0400
committerAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-05-01 01:08:03 -0400
commit83a71d464887f4b6cf9124d2f8c565e6f17f2bd3 (patch)
treeca86805900a974f684dc5531311a53e4836ec784 /nexgb/xgbgen/go_struct.go
parent73154769b3eba60fe48a7c08882e8e64b1545e3f (diff)
downloadhaven-83a71d464887f4b6cf9124d2f8c565e6f17f2bd3.tar.gz
haven-83a71d464887f4b6cf9124d2f8c565e6f17f2bd3.tar.xz
haven-83a71d464887f4b6cf9124d2f8c565e6f17f2bd3.zip
unions, events and errors... oh my
Diffstat (limited to 'nexgb/xgbgen/go_struct.go')
-rw-r--r--nexgb/xgbgen/go_struct.go9
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("")
}