mirror of
https://github.com/bitmagnet-io/bitmagnet.git
synced 2026-07-24 13:11:05 -04:00
226 lines
5.2 KiB
Go
226 lines
5.2 KiB
Go
// Code generated by go-enum DO NOT EDIT.
|
|
// Version:
|
|
// Revision:
|
|
// Build Date:
|
|
// Built By:
|
|
|
|
package model
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
VideoCodecH264 VideoCodec = "H264"
|
|
VideoCodecX264 VideoCodec = "x264"
|
|
VideoCodecX265 VideoCodec = "x265"
|
|
VideoCodecXviD VideoCodec = "XviD"
|
|
VideoCodecDivX VideoCodec = "DivX"
|
|
VideoCodecMPEG2 VideoCodec = "MPEG2"
|
|
VideoCodecMPEG4 VideoCodec = "MPEG4"
|
|
)
|
|
|
|
var ErrInvalidVideoCodec = fmt.Errorf("not a valid VideoCodec, try [%s]", strings.Join(_VideoCodecNames, ", "))
|
|
|
|
var _VideoCodecNames = []string{
|
|
string(VideoCodecH264),
|
|
string(VideoCodecX264),
|
|
string(VideoCodecX265),
|
|
string(VideoCodecXviD),
|
|
string(VideoCodecDivX),
|
|
string(VideoCodecMPEG2),
|
|
string(VideoCodecMPEG4),
|
|
}
|
|
|
|
// VideoCodecNames returns a list of possible string values of VideoCodec.
|
|
func VideoCodecNames() []string {
|
|
tmp := make([]string, len(_VideoCodecNames))
|
|
copy(tmp, _VideoCodecNames)
|
|
return tmp
|
|
}
|
|
|
|
// VideoCodecValues returns a list of the values for VideoCodec
|
|
func VideoCodecValues() []VideoCodec {
|
|
return []VideoCodec{
|
|
VideoCodecH264,
|
|
VideoCodecX264,
|
|
VideoCodecX265,
|
|
VideoCodecXviD,
|
|
VideoCodecDivX,
|
|
VideoCodecMPEG2,
|
|
VideoCodecMPEG4,
|
|
}
|
|
}
|
|
|
|
// String implements the Stringer interface.
|
|
func (x VideoCodec) String() string {
|
|
return string(x)
|
|
}
|
|
|
|
// IsValid provides a quick way to determine if the typed value is
|
|
// part of the allowed enumerated values
|
|
func (x VideoCodec) IsValid() bool {
|
|
_, err := ParseVideoCodec(string(x))
|
|
return err == nil
|
|
}
|
|
|
|
var _VideoCodecValue = map[string]VideoCodec{
|
|
"H264": VideoCodecH264,
|
|
"h264": VideoCodecH264,
|
|
"x264": VideoCodecX264,
|
|
"x265": VideoCodecX265,
|
|
"XviD": VideoCodecXviD,
|
|
"xvid": VideoCodecXviD,
|
|
"DivX": VideoCodecDivX,
|
|
"divx": VideoCodecDivX,
|
|
"MPEG2": VideoCodecMPEG2,
|
|
"mpeg2": VideoCodecMPEG2,
|
|
"MPEG4": VideoCodecMPEG4,
|
|
"mpeg4": VideoCodecMPEG4,
|
|
}
|
|
|
|
// ParseVideoCodec attempts to convert a string to a VideoCodec.
|
|
func ParseVideoCodec(name string) (VideoCodec, error) {
|
|
if x, ok := _VideoCodecValue[name]; ok {
|
|
return x, nil
|
|
}
|
|
// Case insensitive parse, do a separate lookup to prevent unnecessary cost of lowercasing a string if we don't need to.
|
|
if x, ok := _VideoCodecValue[strings.ToLower(name)]; ok {
|
|
return x, nil
|
|
}
|
|
return VideoCodec(""), fmt.Errorf("%s is %w", name, ErrInvalidVideoCodec)
|
|
}
|
|
|
|
// MarshalText implements the text marshaller method.
|
|
func (x VideoCodec) MarshalText() ([]byte, error) {
|
|
return []byte(string(x)), nil
|
|
}
|
|
|
|
// UnmarshalText implements the text unmarshaller method.
|
|
func (x *VideoCodec) UnmarshalText(text []byte) error {
|
|
tmp, err := ParseVideoCodec(string(text))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*x = tmp
|
|
return nil
|
|
}
|
|
|
|
var errVideoCodecNilPtr = errors.New("value pointer is nil") // one per type for package clashes
|
|
|
|
// Scan implements the Scanner interface.
|
|
func (x *VideoCodec) Scan(value interface{}) (err error) {
|
|
if value == nil {
|
|
*x = VideoCodec("")
|
|
return
|
|
}
|
|
|
|
// A wider range of scannable types.
|
|
// driver.Value values at the top of the list for expediency
|
|
switch v := value.(type) {
|
|
case string:
|
|
*x, err = ParseVideoCodec(v)
|
|
case []byte:
|
|
*x, err = ParseVideoCodec(string(v))
|
|
case VideoCodec:
|
|
*x = v
|
|
case *VideoCodec:
|
|
if v == nil {
|
|
return errVideoCodecNilPtr
|
|
}
|
|
*x = *v
|
|
case *string:
|
|
if v == nil {
|
|
return errVideoCodecNilPtr
|
|
}
|
|
*x, err = ParseVideoCodec(*v)
|
|
default:
|
|
return errors.New("invalid type for VideoCodec")
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// Value implements the driver Valuer interface.
|
|
func (x VideoCodec) Value() (driver.Value, error) {
|
|
return x.String(), nil
|
|
}
|
|
|
|
type NullVideoCodec struct {
|
|
VideoCodec VideoCodec
|
|
Valid bool
|
|
Set bool
|
|
}
|
|
|
|
func NewNullVideoCodec(val interface{}) (x NullVideoCodec) {
|
|
err := x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
|
_ = err // make any errcheck linters happy
|
|
return
|
|
}
|
|
|
|
// Scan implements the Scanner interface.
|
|
func (x *NullVideoCodec) Scan(value interface{}) (err error) {
|
|
if value == nil {
|
|
x.VideoCodec, x.Valid = VideoCodec(""), false
|
|
return
|
|
}
|
|
|
|
err = x.VideoCodec.Scan(value)
|
|
x.Valid = (err == nil)
|
|
return
|
|
}
|
|
|
|
// Value implements the driver Valuer interface.
|
|
func (x NullVideoCodec) Value() (driver.Value, error) {
|
|
if !x.Valid {
|
|
return nil, nil
|
|
}
|
|
return x.VideoCodec.String(), nil
|
|
}
|
|
|
|
// MarshalJSON correctly serializes a NullVideoCodec to JSON.
|
|
func (n NullVideoCodec) MarshalJSON() ([]byte, error) {
|
|
const nullStr = "null"
|
|
if n.Valid {
|
|
return json.Marshal(n.VideoCodec)
|
|
}
|
|
return []byte(nullStr), nil
|
|
}
|
|
|
|
// UnmarshalJSON correctly deserializes a NullVideoCodec from JSON.
|
|
func (n *NullVideoCodec) UnmarshalJSON(b []byte) error {
|
|
n.Set = true
|
|
var x interface{}
|
|
err := json.Unmarshal(b, &x)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = n.Scan(x)
|
|
return err
|
|
}
|
|
|
|
// MarshalGQL correctly serializes a NullVideoCodec to GraphQL.
|
|
func (n NullVideoCodec) MarshalGQL(w io.Writer) {
|
|
bytes, err := json.Marshal(n)
|
|
if err == nil {
|
|
_, _ = w.Write(bytes)
|
|
}
|
|
}
|
|
|
|
// UnmarshalGQL correctly deserializes a NullVideoCodec from GraphQL.
|
|
func (n *NullVideoCodec) UnmarshalGQL(v any) error {
|
|
if v == nil {
|
|
return nil
|
|
}
|
|
str, ok := v.(string)
|
|
if !ok {
|
|
return errors.New("value is not a string")
|
|
}
|
|
return n.UnmarshalJSON([]byte(str))
|
|
}
|