diff --git a/gentests/bindata/bindata.go b/gentests/bindata/bindata.go index 9e55e18..829a4f1 100644 --- a/gentests/bindata/bindata.go +++ b/gentests/bindata/bindata.go @@ -2,67 +2,8 @@ package bindata -import ( - "bytes" - "encoding/base64" - "encoding/hex" - "encoding/xml" -) - type Bindata struct { HexData []byte `xml:"hexData"` B64Data []byte `xml:"b64Data"` Filename string `xml:"filename"` } - -func (t *Bindata) MarshalXML(e *xml.Encoder, start xml.StartElement) error { - type T Bindata - var layout struct { - *T - HexData *xsdHexBinary `xml:"hexData"` - B64Data *xsdBase64Binary `xml:"b64Data"` - } - layout.T = (*T)(t) - layout.HexData = (*xsdHexBinary)(&layout.T.HexData) - layout.B64Data = (*xsdBase64Binary)(&layout.T.B64Data) - return e.EncodeElement(layout, start) -} -func (t *Bindata) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { - type T Bindata - var overlay struct { - *T - HexData *xsdHexBinary `xml:"hexData"` - B64Data *xsdBase64Binary `xml:"b64Data"` - } - overlay.T = (*T)(t) - overlay.HexData = (*xsdHexBinary)(&overlay.T.HexData) - overlay.B64Data = (*xsdBase64Binary)(&overlay.T.B64Data) - return d.DecodeElement(&overlay, &start) -} - -type xsdBase64Binary []byte - -func (b *xsdBase64Binary) UnmarshalText(text []byte) (err error) { - *b, err = base64.StdEncoding.DecodeString(string(text)) - return -} -func (b xsdBase64Binary) MarshalText() ([]byte, error) { - var buf bytes.Buffer - enc := base64.NewEncoder(base64.StdEncoding, &buf) - enc.Write([]byte(b)) - enc.Close() - return buf.Bytes(), nil -} - -type xsdHexBinary []byte - -func (b *xsdHexBinary) UnmarshalText(text []byte) (err error) { - *b, err = hex.DecodeString(string(text)) - return -} -func (b xsdHexBinary) MarshalText() ([]byte, error) { - n := hex.EncodedLen(len(b)) - buf := make([]byte, n) - hex.Encode(buf, []byte(b)) - return buf, nil -} diff --git a/xsdgen/builtin.go b/xsdgen/builtin.go index ab07b39..fd145ac 100644 --- a/xsdgen/builtin.go +++ b/xsdgen/builtin.go @@ -21,7 +21,7 @@ func nonTrivialBuiltin(t xsd.Type) bool { return false } switch b { - case xsd.Base64Binary, xsd.HexBinary, + case //xsd.Base64Binary, xsd.HexBinary, xsd.Date, xsd.Time, xsd.DateTime, xsd.GDay, xsd.GMonth, xsd.GMonthDay, xsd.GYear, xsd.GYearMonth: return true diff --git a/xsdgen/config.go b/xsdgen/config.go index a20b1e1..95d0d3b 100644 --- a/xsdgen/config.go +++ b/xsdgen/config.go @@ -681,58 +681,59 @@ func (cfg *Config) addStandardHelpers() { } } - cfg.helperTypes[xsd.XMLName(xsd.HexBinary)] = spec{ - name: "xsd" + xsd.HexBinary.String(), - expr: builtinExpr(xsd.HexBinary), - private: true, - xsdType: xsd.HexBinary, - methods: []*ast.FuncDecl{ - gen.Func("UnmarshalText"). - Receiver("b *xsd" + xsd.HexBinary.String()). - Args("text []byte"). - Returns("err error"). - Body(` - *b, err = hex.DecodeString(string(text)) - return - `).MustDecl(), - gen.Func("MarshalText"). - Receiver("b xsd"+xsd.HexBinary.String()). - Returns("[]byte", "error"). - Body(` - n := hex.EncodedLen(len(b)) - buf := make([]byte, n) - hex.Encode(buf, []byte(b)) - return buf, nil - `).MustDecl(), - }, - } - - cfg.helperTypes[xsd.XMLName(xsd.Base64Binary)] = spec{ - name: "xsd" + xsd.Base64Binary.String(), - expr: builtinExpr(xsd.Base64Binary), - private: true, - xsdType: xsd.Base64Binary, - methods: []*ast.FuncDecl{ - gen.Func("UnmarshalText"). - Receiver("b *xsd" + xsd.Base64Binary.String()). - Args("text []byte"). - Returns("err error"). - Body(` - *b, err = base64.StdEncoding.DecodeString(string(text)) - return - `).MustDecl(), - gen.Func("MarshalText"). - Receiver("b xsd"+xsd.Base64Binary.String()). - Returns("[]byte", "error"). - Body(` - var buf bytes.Buffer - enc := base64.NewEncoder(base64.StdEncoding, &buf) - enc.Write([]byte(b)) - enc.Close() - return buf.Bytes(), nil - `).MustDecl(), - }, - } + /* + cfg.helperTypes[xsd.XMLName(xsd.HexBinary)] = spec{ + name: "xsd" + xsd.HexBinary.String(), + expr: builtinExpr(xsd.HexBinary), + private: true, + xsdType: xsd.HexBinary, + methods: []*ast.FuncDecl{ + gen.Func("UnmarshalText"). + Receiver("b *xsd" + xsd.HexBinary.String()). + Args("text []byte"). + Returns("err error"). + Body(` + *b, err = hex.DecodeString(string(text)) + return + `).MustDecl(), + gen.Func("MarshalText"). + Receiver("b xsd"+xsd.HexBinary.String()). + Returns("[]byte", "error"). + Body(` + n := hex.EncodedLen(len(b)) + buf := make([]byte, n) + hex.Encode(buf, []byte(b)) + return buf, nil + `).MustDecl(), + }, + } + + cfg.helperTypes[xsd.XMLName(xsd.Base64Binary)] = spec{ + name: "xsd" + xsd.Base64Binary.String(), + expr: builtinExpr(xsd.Base64Binary), + private: true, + xsdType: xsd.Base64Binary, + methods: []*ast.FuncDecl{ + gen.Func("UnmarshalText"). + Receiver("b *xsd" + xsd.Base64Binary.String()). + Args("text []byte"). + Returns("err error"). + Body(` + *b, err = base64.StdEncoding.DecodeString(string(text)) + return + `).MustDecl(), + gen.Func("MarshalText"). + Receiver("b xsd"+xsd.Base64Binary.String()). + Returns("[]byte", "error"). + Body(` + var buf bytes.Buffer + enc := base64.NewEncoder(base64.StdEncoding, &buf) + enc.Write([]byte(b)) + enc.Close() + return buf.Bytes(), nil + `).MustDecl(), + }, + } */ } // SOAP arrays (and other similar types) are complex types with a single