feature: added array list marshalling
This commit is contained in:
parent
e6ee7860b3
commit
a26b61975d
20
pkg/collections/array_list/array_list_json.go
Normal file
20
pkg/collections/array_list/array_list_json.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package array_list
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (a *ArrayList[T]) MarshalJSON() ([]byte, error) {
|
||||||
|
return json.Marshal(a.content[:a.size])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ArrayList[T]) UnmarshalJSON(data []byte) error {
|
||||||
|
var content []T
|
||||||
|
if err := json.Unmarshal(data, &content); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
a.content = content
|
||||||
|
a.size = len(content)
|
||||||
|
return nil
|
||||||
|
}
|
20
pkg/collections/array_list/array_list_xml.go
Normal file
20
pkg/collections/array_list/array_list_xml.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package array_list
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (a *ArrayList[T]) MarshalXML() ([]byte, error) {
|
||||||
|
return json.Marshal(a.content[:a.size])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ArrayList[T]) UnmarshalXML(data []byte) error {
|
||||||
|
var content []T
|
||||||
|
if err := json.Unmarshal(data, &content); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
a.content = content
|
||||||
|
a.size = len(content)
|
||||||
|
return nil
|
||||||
|
}
|
20
pkg/collections/array_list/array_list_yaml.go
Normal file
20
pkg/collections/array_list/array_list_yaml.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package array_list
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (a *ArrayList[T]) MarshalYAML() ([]byte, error) {
|
||||||
|
return json.Marshal(a.content[:a.size])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *ArrayList[T]) UnmarshalYAML(data []byte) error {
|
||||||
|
var content []T
|
||||||
|
if err := json.Unmarshal(data, &content); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
a.content = content
|
||||||
|
a.size = len(content)
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user