2020-06-16 07:56:06 +00:00
|
|
|
/*
|
|
|
|
Package binary provides binary serialization routines.
|
|
|
|
*/
|
|
|
|
package binary
|
|
|
|
|
2021-02-05 16:02:09 +00:00
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/neogointernal"
|
|
|
|
)
|
|
|
|
|
2020-06-16 07:56:06 +00:00
|
|
|
// Serialize serializes any given item into a byte slice. It works for all
|
|
|
|
// regular VM types (not ones from interop package) and allows to save them in
|
|
|
|
// storage or pass into Notify and then Deserialize them on the next run or in
|
|
|
|
// the external event receiver. It uses `System.Binary.Serialize` syscall.
|
|
|
|
func Serialize(item interface{}) []byte {
|
2021-02-05 16:02:09 +00:00
|
|
|
return neogointernal.Syscall1("System.Binary.Serialize", item).([]byte)
|
2020-06-16 07:56:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Deserialize unpacks previously serialized value from a byte slice, it's the
|
|
|
|
// opposite of Serialize. It uses `System.Binary.Deserialize` syscall.
|
|
|
|
func Deserialize(b []byte) interface{} {
|
2021-02-05 16:02:09 +00:00
|
|
|
return neogointernal.Syscall1("System.Binary.Deserialize", b)
|
2020-06-16 07:56:06 +00:00
|
|
|
}
|