go.ligato.io/vpp-agent/v3@v3.5.0/proto/ligato/kvscheduler/value_status.go (about) 1 // Copyright (c) 2019 Cisco and/or its affiliates. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at: 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package kvscheduler 16 17 import ( 18 "encoding/json" 19 ) 20 21 // MarshalJSON ensures data is correctly marshaled 22 func (x ValueState) MarshalJSON() ([]byte, error) { 23 return json.Marshal(x.String()) 24 } 25 26 // UnmarshalJSON ensures that data is correctly unmarshaled 27 func (x *ValueState) UnmarshalJSON(b []byte) error { 28 if b[0] == '"' { 29 var s string 30 if err := json.Unmarshal(b, &s); err != nil { 31 return err 32 } 33 *x = ValueState(ValueState_value[s]) 34 } else { 35 var n int 36 if err := json.Unmarshal(b, &n); err != nil { 37 return err 38 } 39 *x = ValueState(n) 40 } 41 return nil 42 } 43 44 // MarshalJSON ensures data is correctly marshaled 45 func (x TxnOperation) MarshalJSON() ([]byte, error) { 46 return json.Marshal(x.String()) 47 } 48 49 // UnmarshalJSON ensures that data is correctly unmarshaled 50 func (x *TxnOperation) UnmarshalJSON(b []byte) error { 51 if b[0] == '"' { 52 var s string 53 if err := json.Unmarshal(b, &s); err != nil { 54 return err 55 } 56 *x = TxnOperation(TxnOperation_value[s]) 57 } else { 58 var n int 59 if err := json.Unmarshal(b, &n); err != nil { 60 return err 61 } 62 *x = TxnOperation(n) 63 } 64 return nil 65 }