aboutsummaryrefslogtreecommitdiff
path: root/nexgb/xgbgen/go_error.go
diff options
context:
space:
mode:
Diffstat (limited to 'nexgb/xgbgen/go_error.go')
-rw-r--r--nexgb/xgbgen/go_error.go30
1 files changed, 24 insertions, 6 deletions
diff --git a/nexgb/xgbgen/go_error.go b/nexgb/xgbgen/go_error.go
index 0cb77cc..493a8b9 100644
--- a/nexgb/xgbgen/go_error.go
+++ b/nexgb/xgbgen/go_error.go
@@ -22,18 +22,36 @@ func (e *ErrorCopy) Define(c *Context) {
c.Putln("")
c.Putln("type %s %s", e.ErrType(), e.Old.(*Error).ErrType())
c.Putln("")
+
+ // Read defines a function that transforms a byte slice into this
+ // error struct.
+ e.Read(c)
+
+ // Write defines a function that transoforms this error struct into
+ // a byte slice.
+ e.Write(c)
+
+ // Makes sure that this error type is an Error interface.
+ c.Putln("func (err %s) ImplementsError() { }", e.ErrType())
+ c.Putln("")
+
+ // Let's the XGB know how to read this error.
+ c.Putln("func init() {")
+ c.Putln("newErrorFuncs[%d] = New%s", e.Number, e.SrcName())
+ c.Putln("}")
+ c.Putln("")
+}
+
+func (e *ErrorCopy) Read(c *Context) {
c.Putln("func New%s(buf []byte) %s {", e.SrcName(), e.ErrType())
c.Putln("return (%s)(New%s(buf))", e.ErrType(), e.Old.SrcName())
c.Putln("}")
c.Putln("")
- c.Putln("func (err %s) ImplementsError() { }", e.ErrType())
- c.Putln("")
+}
+
+func (e *ErrorCopy) Write(c *Context) {
c.Putln("func (err %s) Bytes() []byte {", e.ErrType())
c.Putln("return (%s)(err).Bytes()", e.Old.(*Error).ErrType())
c.Putln("}")
c.Putln("")
- c.Putln("func init() {")
- c.Putln("newErrorFuncs[%d] = New%s", e.Number, e.SrcName())
- c.Putln("}")
- c.Putln("")
}