2016-12-18 05:21:29 +00:00
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/portainer/portainer"
|
|
|
|
|
2016-12-25 20:34:02 +00:00
|
|
|
"encoding/binary"
|
2016-12-18 05:21:29 +00:00
|
|
|
"encoding/json"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MarshalUser encodes a user to binary format.
|
|
|
|
func MarshalUser(user *portainer.User) ([]byte, error) {
|
|
|
|
return json.Marshal(user)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalUser decodes a user from a binary data.
|
|
|
|
func UnmarshalUser(data []byte, user *portainer.User) error {
|
|
|
|
return json.Unmarshal(data, user)
|
|
|
|
}
|
2016-12-25 20:34:02 +00:00
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
// MarshalTeam encodes a team to binary format.
|
|
|
|
func MarshalTeam(team *portainer.Team) ([]byte, error) {
|
|
|
|
return json.Marshal(team)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalTeam decodes a team from a binary data.
|
|
|
|
func UnmarshalTeam(data []byte, team *portainer.Team) error {
|
|
|
|
return json.Unmarshal(data, team)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarshalTeamMembership encodes a team membership to binary format.
|
|
|
|
func MarshalTeamMembership(membership *portainer.TeamMembership) ([]byte, error) {
|
|
|
|
return json.Marshal(membership)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalTeamMembership decodes a team membership from a binary data.
|
|
|
|
func UnmarshalTeamMembership(data []byte, membership *portainer.TeamMembership) error {
|
|
|
|
return json.Unmarshal(data, membership)
|
|
|
|
}
|
|
|
|
|
2016-12-25 20:34:02 +00:00
|
|
|
// MarshalEndpoint encodes an endpoint to binary format.
|
|
|
|
func MarshalEndpoint(endpoint *portainer.Endpoint) ([]byte, error) {
|
|
|
|
return json.Marshal(endpoint)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalEndpoint decodes an endpoint from a binary data.
|
|
|
|
func UnmarshalEndpoint(data []byte, endpoint *portainer.Endpoint) error {
|
|
|
|
return json.Unmarshal(data, endpoint)
|
|
|
|
}
|
|
|
|
|
2017-03-12 16:24:15 +00:00
|
|
|
// MarshalResourceControl encodes a resource control object to binary format.
|
|
|
|
func MarshalResourceControl(rc *portainer.ResourceControl) ([]byte, error) {
|
|
|
|
return json.Marshal(rc)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalResourceControl decodes a resource control object from a binary data.
|
|
|
|
func UnmarshalResourceControl(data []byte, rc *portainer.ResourceControl) error {
|
|
|
|
return json.Unmarshal(data, rc)
|
|
|
|
}
|
|
|
|
|
2017-06-01 08:14:55 +00:00
|
|
|
// MarshalSettings encodes a settings object to binary format.
|
|
|
|
func MarshalSettings(settings *portainer.Settings) ([]byte, error) {
|
|
|
|
return json.Marshal(settings)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalSettings decodes a settings object from a binary data.
|
|
|
|
func UnmarshalSettings(data []byte, settings *portainer.Settings) error {
|
|
|
|
return json.Unmarshal(data, settings)
|
|
|
|
}
|
|
|
|
|
2016-12-25 20:34:02 +00:00
|
|
|
// 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
|
|
|
|
}
|