mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 07:19:41 +02:00
25 lines
642 B
Go
25 lines
642 B
Go
package internal
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"encoding/json"
|
|
)
|
|
|
|
// MarshalObject encodes an object to binary format
|
|
func MarshalObject(object interface{}) ([]byte, error) {
|
|
return json.Marshal(object)
|
|
}
|
|
|
|
// UnmarshalObject decodes an object from binary data
|
|
func UnmarshalObject(data []byte, object interface{}) error {
|
|
return json.Unmarshal(data, object)
|
|
}
|
|
|
|
// Itob returns an 8-byte big endian representation of v.
|
|
// This function is typically used for encoding integer IDs to byte slices
|
|
// so that they can be used as BoltDB keys.
|
|
func Itob(v int) []byte {
|
|
b := make([]byte, 8)
|
|
binary.BigEndian.PutUint64(b, uint64(v))
|
|
return b
|
|
}
|