2022-11-10 07:35:38 +01:00
|
|
|
// Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
|
|
|
|
// All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io"
|
2022-11-10 13:37:53 +01:00
|
|
|
|
|
|
|
"github.com/ClusterCockpit/cc-backend/pkg/schema"
|
2022-11-10 07:35:38 +01:00
|
|
|
)
|
|
|
|
|
2023-03-10 12:14:33 +01:00
|
|
|
func DecodeJobData(r io.Reader) (*JobData, error) {
|
2022-11-10 07:35:38 +01:00
|
|
|
var d JobData
|
|
|
|
if err := json.NewDecoder(r).Decode(&d); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-03-10 12:14:33 +01:00
|
|
|
return &d, nil
|
2022-11-10 07:35:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func DecodeJobMeta(r io.Reader) (*JobMeta, error) {
|
|
|
|
var d JobMeta
|
|
|
|
if err := json.NewDecoder(r).Decode(&d); err != nil {
|
2023-03-10 12:14:33 +01:00
|
|
|
return nil, err
|
2022-11-10 07:35:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return &d, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func DecodeCluster(r io.Reader) (*Cluster, error) {
|
|
|
|
var c Cluster
|
|
|
|
if err := json.NewDecoder(r).Decode(&c); err != nil {
|
2023-03-10 12:14:33 +01:00
|
|
|
return nil, err
|
2022-11-10 07:35:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return &c, nil
|
|
|
|
}
|
|
|
|
|
2023-03-10 12:14:33 +01:00
|
|
|
func EncodeJobData(w io.Writer, d *schema.JobData) error {
|
2022-11-10 07:35:38 +01:00
|
|
|
// Sanitize parameters
|
|
|
|
if err := json.NewEncoder(w).Encode(d); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-03-10 12:14:33 +01:00
|
|
|
func EncodeJobMeta(w io.Writer, d *schema.JobMeta) error {
|
2022-11-10 07:35:38 +01:00
|
|
|
// Sanitize parameters
|
|
|
|
if err := json.NewEncoder(w).Encode(d); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2022-11-10 13:37:53 +01:00
|
|
|
|
|
|
|
func EncodeCluster(w io.Writer, c *schema.Cluster) error {
|
|
|
|
// Sanitize parameters
|
|
|
|
if err := json.NewEncoder(w).Encode(c); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|