Implement SOAP "bin.base64" marshalling.
This commit is contained in:
parent
aba95ad90c
commit
3c28ba0b35
@ -1,6 +1,7 @@
|
|||||||
package soap
|
package soap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -396,3 +397,13 @@ func UnmarshalBoolean(s string) (bool, error) {
|
|||||||
}
|
}
|
||||||
return false, fmt.Errorf("soap boolean: %q is not a valid boolean value", s)
|
return false, fmt.Errorf("soap boolean: %q is not a valid boolean value", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalBinBase64 marshals []byte to SOAP "bin.base64" type.
|
||||||
|
func MarshalBinBase64(v []byte) (string, error) {
|
||||||
|
return base64.StdEncoding.EncodeToString(v), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalBinBase64 unmarshals []byte from the SOAP "bin.base64" type.
|
||||||
|
func UnmarshalBinBase64(s string) ([]byte, error) {
|
||||||
|
return base64.StdEncoding.DecodeString(s)
|
||||||
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package soap
|
package soap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"math"
|
"math"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -146,6 +147,18 @@ func (v BooleanTest) Equal(result interface{}) bool {
|
|||||||
return bool(v) == result.(bool)
|
return bool(v) == result.(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BinBase64Test []byte
|
||||||
|
|
||||||
|
func (v BinBase64Test) Marshal() (string, error) {
|
||||||
|
return MarshalBinBase64([]byte(v))
|
||||||
|
}
|
||||||
|
func (v BinBase64Test) Unmarshal(s string) (interface{}, error) {
|
||||||
|
return UnmarshalBinBase64(s)
|
||||||
|
}
|
||||||
|
func (v BinBase64Test) Equal(result interface{}) bool {
|
||||||
|
return bytes.Equal([]byte(v), result.([]byte))
|
||||||
|
}
|
||||||
|
|
||||||
func Test(t *testing.T) {
|
func Test(t *testing.T) {
|
||||||
const time010203 time.Duration = (1*3600 + 2*60 + 3) * time.Second
|
const time010203 time.Duration = (1*3600 + 2*60 + 3) * time.Second
|
||||||
const time0102 time.Duration = (1*3600 + 2*60) * time.Second
|
const time0102 time.Duration = (1*3600 + 2*60) * time.Second
|
||||||
@ -257,6 +270,12 @@ func Test(t *testing.T) {
|
|||||||
{str: "other", value: BooleanTest(false), noMarshal: true, wantUnmarshalErr: true},
|
{str: "other", value: BooleanTest(false), noMarshal: true, wantUnmarshalErr: true},
|
||||||
{str: "2", value: BooleanTest(false), noMarshal: true, wantUnmarshalErr: true},
|
{str: "2", value: BooleanTest(false), noMarshal: true, wantUnmarshalErr: true},
|
||||||
{str: "-1", value: BooleanTest(false), noMarshal: true, wantUnmarshalErr: true},
|
{str: "-1", value: BooleanTest(false), noMarshal: true, wantUnmarshalErr: true},
|
||||||
|
|
||||||
|
// bin.base64
|
||||||
|
{str: "", value: BinBase64Test{}},
|
||||||
|
{str: "YQ==", value: BinBase64Test("a")},
|
||||||
|
{str: "TG9uZ2VyIFN0cmluZy4=", value: BinBase64Test("Longer String.")},
|
||||||
|
{str: "TG9uZ2VyIEFsaWduZWQu", value: BinBase64Test("Longer Aligned.")},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate extra test cases from convTests that implement duper.
|
// Generate extra test cases from convTests that implement duper.
|
||||||
|
Loading…
Reference in New Issue
Block a user