diff options
author | Andrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu> | 2012-05-10 17:01:42 -0400 |
---|---|---|
committer | Andrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu> | 2012-05-10 17:01:42 -0400 |
commit | 0c50dc6241fa21712e041cfa2bfb9db4ccaef10a (patch) | |
tree | 90a3200414c8ad6df8e7983a8e73fedfbe2b324e /nexgb/xgbgen/go_single_field.go | |
parent | e239bb3c68a4981a3916534203c2fbd6b96f593c (diff) | |
download | haven-0c50dc6241fa21712e041cfa2bfb9db4ccaef10a.tar.gz haven-0c50dc6241fa21712e041cfa2bfb9db4ccaef10a.tar.xz haven-0c50dc6241fa21712e041cfa2bfb9db4ccaef10a.zip |
a huge commit. splitting extensions into their own sub-packages.
Diffstat (limited to 'nexgb/xgbgen/go_single_field.go')
-rw-r--r-- | nexgb/xgbgen/go_single_field.go | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/nexgb/xgbgen/go_single_field.go b/nexgb/xgbgen/go_single_field.go index 433ebe3..3e3fa53 100644 --- a/nexgb/xgbgen/go_single_field.go +++ b/nexgb/xgbgen/go_single_field.go @@ -12,17 +12,17 @@ func (f *SingleField) Define(c *Context) { func ReadSimpleSingleField(c *Context, name string, typ Type) { switch t := typ.(type) { case *Resource: - c.Putln("%s = %s(Get32(buf[b:]))", name, t.SrcName()) + c.Putln("%s = %s(xgb.Get32(buf[b:]))", name, t.SrcName()) case *TypeDef: switch t.Size().Eval() { case 1: c.Putln("%s = %s(buf[b])", name, t.SrcName()) case 2: - c.Putln("%s = %s(Get16(buf[b:]))", name, t.SrcName()) + c.Putln("%s = %s(xgb.Get16(buf[b:]))", name, t.SrcName()) case 4: - c.Putln("%s = %s(Get32(buf[b:]))", name, t.SrcName()) + c.Putln("%s = %s(xgb.Get32(buf[b:]))", name, t.SrcName()) case 8: - c.Putln("%s = %s(Get64(buf[b:]))", name, t.SrcName()) + c.Putln("%s = %s(xgb.Get64(buf[b:]))", name, t.SrcName()) } case *Base: // If this is a bool, stop short and do something special. @@ -40,11 +40,11 @@ func ReadSimpleSingleField(c *Context, name string, typ Type) { case 1: val = fmt.Sprintf("buf[b]") case 2: - val = fmt.Sprintf("Get16(buf[b:])") + val = fmt.Sprintf("xgb.Get16(buf[b:])") case 4: - val = fmt.Sprintf("Get32(buf[b:])") + val = fmt.Sprintf("xgb.Get32(buf[b:])") case 8: - val = fmt.Sprintf("Get64(buf[b:])") + val = fmt.Sprintf("xgb.Get64(buf[b:])") } // We need to convert base types if they aren't uintXX or byte @@ -71,10 +71,10 @@ func (f *SingleField) Read(c *Context, prefix string) { ReadSimpleSingleField(c, fmt.Sprintf("%s%s", prefix, f.SrcName()), t) case *Struct: c.Putln("%s%s = %s{}", prefix, f.SrcName(), t.SrcName()) - c.Putln("b += Read%s(buf[b:], &%s%s)", t.SrcName(), prefix, f.SrcName()) + c.Putln("b += %sRead(buf[b:], &%s%s)", t.SrcName(), prefix, f.SrcName()) case *Union: c.Putln("%s%s = %s{}", prefix, f.SrcName(), t.SrcName()) - c.Putln("b += Read%s(buf[b:], &%s%s)", t.SrcName(), prefix, f.SrcName()) + c.Putln("b += %sRead(buf[b:], &%s%s)", t.SrcName(), prefix, f.SrcName()) default: log.Panicf("Cannot read field '%s' with %T type.", f.XmlName(), f.Type) } @@ -83,17 +83,17 @@ func (f *SingleField) Read(c *Context, prefix string) { func WriteSimpleSingleField(c *Context, name string, typ Type) { switch t := typ.(type) { case *Resource: - c.Putln("Put32(buf[b:], uint32(%s))", name) + c.Putln("xgb.Put32(buf[b:], uint32(%s))", name) case *TypeDef: switch t.Size().Eval() { case 1: c.Putln("buf[b] = byte(%s)", name) case 2: - c.Putln("Put16(buf[b:], uint16(%s))", name) + c.Putln("xgb.Put16(buf[b:], uint16(%s))", name) case 4: - c.Putln("Put32(buf[b:], uint32(%s))", name) + c.Putln("xgb.Put32(buf[b:], uint32(%s))", name) case 8: - c.Putln("Put64(buf[b:], uint64(%s))", name) + c.Putln("xgb.Put64(buf[b:], uint64(%s))", name) } case *Base: // If this is a bool, stop short and do something special. @@ -115,21 +115,21 @@ func WriteSimpleSingleField(c *Context, name string, typ Type) { } case 2: if t.SrcName() != "uint16" { - c.Putln("Put16(buf[b:], uint16(%s))", name) + c.Putln("xgb.Put16(buf[b:], uint16(%s))", name) } else { - c.Putln("Put16(buf[b:], %s)", name) + c.Putln("xgb.Put16(buf[b:], %s)", name) } case 4: if t.SrcName() != "uint32" { - c.Putln("Put32(buf[b:], uint32(%s))", name) + c.Putln("xgb.Put32(buf[b:], uint32(%s))", name) } else { - c.Putln("Put32(buf[b:], %s)", name) + c.Putln("xgb.Put32(buf[b:], %s)", name) } case 8: if t.SrcName() != "uint64" { - c.Putln("Put64(buf[b:], uint64(%s))", name) + c.Putln("xgb.Put64(buf[b:], uint64(%s))", name) } else { - c.Putln("Put64(buf[b:], %s)", name) + c.Putln("xgb.Put64(buf[b:], %s)", name) } } default: @@ -152,13 +152,13 @@ func (f *SingleField) Write(c *Context, prefix string) { c.Putln("{") c.Putln("unionBytes := %s%s.Bytes()", prefix, f.SrcName()) c.Putln("copy(buf[b:], unionBytes)") - c.Putln("b += pad(len(unionBytes))") + c.Putln("b += xgb.Pad(len(unionBytes))") c.Putln("}") case *Struct: c.Putln("{") c.Putln("structBytes := %s%s.Bytes()", prefix, f.SrcName()) c.Putln("copy(buf[b:], structBytes)") - c.Putln("b += pad(len(structBytes))") + c.Putln("b += xgb.Pad(len(structBytes))") c.Putln("}") default: log.Fatalf("Cannot read field '%s' with %T type.", f.XmlName(), f.Type) |