29 lines
664 B
Go
29 lines
664 B
Go
|
package utio
|
||
|
|
||
|
import "bytes"
|
||
|
|
||
|
// DecodeFromString d the bytes of s to fn.
|
||
|
func DecodeFromString(s string, d Decoder) error {
|
||
|
return ReadFromString(s, d.Decode)
|
||
|
}
|
||
|
|
||
|
// ReadFromString supplies the bytes of s to fn.
|
||
|
func ReadFromString(s string, fn ReadFunc) error {
|
||
|
return fn(bytes.NewBufferString(s))
|
||
|
}
|
||
|
|
||
|
// EncodeToString returns the encoded string value
|
||
|
func EncodeToString(e Encoder) (string, error) {
|
||
|
return WriteToString(e.Encode)
|
||
|
}
|
||
|
|
||
|
// WriteToString returns the string value of the data written to fn.
|
||
|
func WriteToString(fn WriteFunc) (string, error) {
|
||
|
var b = &bytes.Buffer{}
|
||
|
var err = fn(b)
|
||
|
if nil != err {
|
||
|
return "", err
|
||
|
}
|
||
|
return b.String(), nil
|
||
|
}
|