// Package serialize ... // // Description : serialize ... // // Author : go_developer@163.com<白茶清欢> // // Date : 2024-10-23 17:06 package serialize import ( "bytes" "gopkg.in/yaml.v3" "io" ) var ( Yml = ownYml{} ) type ownYml struct{} func (o *ownYml) MarshalForByte(input any) ([]byte, error) { return yaml.Marshal(input) } func (o *ownYml) MarshalForByteIgnoreError(input any) []byte { byteData, _ := o.MarshalForByte(input) return byteData } func (o *ownYml) MarshalForString(input any) (string, error) { byteData, err := o.MarshalForByte(input) if nil != err { return "", err } return string(byteData), nil } func (o *ownYml) MarshalForStringIgnoreError(input any) string { return string(o.MarshalForByteIgnoreError(input)) } func (o *ownYml) UnmarshalWithNumber(byteData []byte, receiver any) error { return yaml.NewDecoder(bytes.NewReader(byteData)).Decode(receiver) } func (o *ownYml) UnmarshalWithNumberIgnoreError(byteData []byte, receiver any) { _ = o.UnmarshalWithNumber(byteData, receiver) return } func (o *ownYml) UnmarshalWithNumberForIOReader(ioReader io.ReadCloser, receiver any) error { return yaml.NewDecoder(ioReader).Decode(receiver) } func (o *ownYml) UnmarshalWithNumberForIOReaderIgnoreError(ioReader io.ReadCloser, receiver any) { _ = o.UnmarshalWithNumberForIOReader(ioReader, receiver) return } func (o *ownYml) UnmarshalWithNumberForString(input string, receiver any) error { return o.UnmarshalWithNumber([]byte(input), receiver) } func (o *ownYml) UnmarshalWithNumberForStringIgnoreError(input string, receiver any) { _ = o.UnmarshalWithNumberForString(input, receiver) return }