aboutsummaryrefslogtreecommitdiff
path: root/nexgb/xgbgen/go_struct.go
diff options
context:
space:
mode:
authorAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-05-03 01:00:01 -0400
committerAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-05-03 01:00:01 -0400
commit5cdae5950c357564300c0ee3fb4dc9e7bbf4946b (patch)
tree1ca6c09455b060b9f607c3e275ac14b5c57bbdc1 /nexgb/xgbgen/go_struct.go
parent39507f86ab0468292c24081a80f41c1799d6b477 (diff)
downloadhaven-5cdae5950c357564300c0ee3fb4dc9e7bbf4946b.tar.gz
haven-5cdae5950c357564300c0ee3fb4dc9e7bbf4946b.tar.xz
haven-5cdae5950c357564300c0ee3fb4dc9e7bbf4946b.zip
holy toldeo... things might actually be working
Diffstat (limited to 'nexgb/xgbgen/go_struct.go')
-rw-r--r--nexgb/xgbgen/go_struct.go19
1 files changed, 12 insertions, 7 deletions
diff --git a/nexgb/xgbgen/go_struct.go b/nexgb/xgbgen/go_struct.go
index 600ebaf..1e43199 100644
--- a/nexgb/xgbgen/go_struct.go
+++ b/nexgb/xgbgen/go_struct.go
@@ -22,8 +22,11 @@ func (s *Struct) Define(c *Context) {
// Write function that writes a list of this struct.
s.WriteList(c)
- // Write function that computes the size of a list of these structs.
- s.WriteListSize(c)
+ // Write function that computes the size of a list of these structs,
+ // IF there is a list field in this struct.
+ if s.HasList() {
+ s.WriteListSize(c)
+ }
}
// Read for a struct creates a function 'ReadStructName' that takes a source
@@ -37,7 +40,8 @@ func (s *Struct) Read(c *Context) {
c.Putln("b := 0")
c.Putln("")
for _, field := range s.Fields {
- field.Read(c)
+ field.Read(c, "v.")
+ c.Putln("")
}
c.Putln("return b")
@@ -68,11 +72,12 @@ 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("v.", ""))
+ c.Putln("buf := make([]byte, %s)", s.Size().Reduce("v."))
c.Putln("b := 0")
c.Putln("")
for _, field := range s.Fields {
- field.Write(c)
+ field.Write(c, "v.")
+ c.Putln("")
}
c.Putln("return buf")
c.Putln("}")
@@ -87,7 +92,7 @@ func (s *Struct) WriteList(c *Context) {
c.Putln("var structBytes []byte")
c.Putln("for _, item := range list {")
c.Putln("structBytes = item.Bytes()")
- c.Putln("copy(buf[b:], len(structBytes))")
+ c.Putln("copy(buf[b:], structBytes)")
c.Putln("b += pad(len(structBytes))")
c.Putln("}")
c.Putln("return b")
@@ -100,7 +105,7 @@ func (s *Struct) WriteListSize(c *Context) {
c.Putln("func %sListSize(list []%s) int {", s.SrcName(), s.SrcName())
c.Putln("size := 0")
c.Putln("for _, item := range list {")
- c.Putln("size += %s", s.Size().Reduce("item.", ""))
+ c.Putln("size += %s", s.Size().Reduce("item."))
c.Putln("}")
c.Putln("return size")
c.Putln("}")