Skip to content

Commit

Permalink
base64 & Hex values are now treated as any other values
Browse files Browse the repository at this point in the history
  • Loading branch information
henryolik committed Oct 13, 2023
1 parent d5bfee3 commit 4fbdede
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 112 deletions.
59 changes: 0 additions & 59 deletions gentests/bindata/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion xsdgen/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
105 changes: 53 additions & 52 deletions xsdgen/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4fbdede

Please sign in to comment.