github.com/pion/webrtc/v4@v4.0.1/pkg/null/null.go (about)

     1  // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
     2  // SPDX-License-Identifier: MIT
     3  
     4  // Package null is used to represent values where the 0 value is significant
     5  // This pattern is common in ECMAScript, this allows us to maintain a matching API
     6  package null
     7  
     8  // Bool is used to represent a bool that may be null
     9  type Bool struct {
    10  	Valid bool
    11  	Bool  bool
    12  }
    13  
    14  // NewBool turns a bool into a valid null.Bool
    15  func NewBool(value bool) Bool {
    16  	return Bool{Valid: true, Bool: value}
    17  }
    18  
    19  // Byte is used to represent a byte that may be null
    20  type Byte struct {
    21  	Valid bool
    22  	Byte  byte
    23  }
    24  
    25  // NewByte turns a byte into a valid null.Byte
    26  func NewByte(value byte) Byte {
    27  	return Byte{Valid: true, Byte: value}
    28  }
    29  
    30  // Complex128 is used to represent a complex128 that may be null
    31  type Complex128 struct {
    32  	Valid      bool
    33  	Complex128 complex128
    34  }
    35  
    36  // NewComplex128 turns a complex128 into a valid null.Complex128
    37  func NewComplex128(value complex128) Complex128 {
    38  	return Complex128{Valid: true, Complex128: value}
    39  }
    40  
    41  // Complex64 is used to represent a complex64 that may be null
    42  type Complex64 struct {
    43  	Valid     bool
    44  	Complex64 complex64
    45  }
    46  
    47  // NewComplex64 turns a complex64 into a valid null.Complex64
    48  func NewComplex64(value complex64) Complex64 {
    49  	return Complex64{Valid: true, Complex64: value}
    50  }
    51  
    52  // Float32 is used to represent a float32 that may be null
    53  type Float32 struct {
    54  	Valid   bool
    55  	Float32 float32
    56  }
    57  
    58  // NewFloat32 turns a float32 into a valid null.Float32
    59  func NewFloat32(value float32) Float32 {
    60  	return Float32{Valid: true, Float32: value}
    61  }
    62  
    63  // Float64 is used to represent a float64 that may be null
    64  type Float64 struct {
    65  	Valid   bool
    66  	Float64 float64
    67  }
    68  
    69  // NewFloat64 turns a float64 into a valid null.Float64
    70  func NewFloat64(value float64) Float64 {
    71  	return Float64{Valid: true, Float64: value}
    72  }
    73  
    74  // Int is used to represent a int that may be null
    75  type Int struct {
    76  	Valid bool
    77  	Int   int
    78  }
    79  
    80  // NewInt turns a int into a valid null.Int
    81  func NewInt(value int) Int {
    82  	return Int{Valid: true, Int: value}
    83  }
    84  
    85  // Int16 is used to represent a int16 that may be null
    86  type Int16 struct {
    87  	Valid bool
    88  	Int16 int16
    89  }
    90  
    91  // NewInt16 turns a int16 into a valid null.Int16
    92  func NewInt16(value int16) Int16 {
    93  	return Int16{Valid: true, Int16: value}
    94  }
    95  
    96  // Int32 is used to represent a int32 that may be null
    97  type Int32 struct {
    98  	Valid bool
    99  	Int32 int32
   100  }
   101  
   102  // NewInt32 turns a int32 into a valid null.Int32
   103  func NewInt32(value int32) Int32 {
   104  	return Int32{Valid: true, Int32: value}
   105  }
   106  
   107  // Int64 is used to represent a int64 that may be null
   108  type Int64 struct {
   109  	Valid bool
   110  	Int64 int64
   111  }
   112  
   113  // NewInt64 turns a int64 into a valid null.Int64
   114  func NewInt64(value int64) Int64 {
   115  	return Int64{Valid: true, Int64: value}
   116  }
   117  
   118  // Int8 is used to represent a int8 that may be null
   119  type Int8 struct {
   120  	Valid bool
   121  	Int8  int8
   122  }
   123  
   124  // NewInt8 turns a int8 into a valid null.Int8
   125  func NewInt8(value int8) Int8 {
   126  	return Int8{Valid: true, Int8: value}
   127  }
   128  
   129  // Rune is used to represent a rune that may be null
   130  type Rune struct {
   131  	Valid bool
   132  	Rune  rune
   133  }
   134  
   135  // NewRune turns a rune into a valid null.Rune
   136  func NewRune(value rune) Rune {
   137  	return Rune{Valid: true, Rune: value}
   138  }
   139  
   140  // String is used to represent a string that may be null
   141  type String struct {
   142  	Valid  bool
   143  	String string
   144  }
   145  
   146  // NewString turns a string into a valid null.String
   147  func NewString(value string) String {
   148  	return String{Valid: true, String: value}
   149  }
   150  
   151  // Uint is used to represent a uint that may be null
   152  type Uint struct {
   153  	Valid bool
   154  	Uint  uint
   155  }
   156  
   157  // NewUint turns a uint into a valid null.Uint
   158  func NewUint(value uint) Uint {
   159  	return Uint{Valid: true, Uint: value}
   160  }
   161  
   162  // Uint16 is used to represent a uint16 that may be null
   163  type Uint16 struct {
   164  	Valid  bool
   165  	Uint16 uint16
   166  }
   167  
   168  // NewUint16 turns a uint16 into a valid null.Uint16
   169  func NewUint16(value uint16) Uint16 {
   170  	return Uint16{Valid: true, Uint16: value}
   171  }
   172  
   173  // Uint32 is used to represent a uint32 that may be null
   174  type Uint32 struct {
   175  	Valid  bool
   176  	Uint32 uint32
   177  }
   178  
   179  // NewUint32 turns a uint32 into a valid null.Uint32
   180  func NewUint32(value uint32) Uint32 {
   181  	return Uint32{Valid: true, Uint32: value}
   182  }
   183  
   184  // Uint64 is used to represent a uint64 that may be null
   185  type Uint64 struct {
   186  	Valid  bool
   187  	Uint64 uint64
   188  }
   189  
   190  // NewUint64 turns a uint64 into a valid null.Uint64
   191  func NewUint64(value uint64) Uint64 {
   192  	return Uint64{Valid: true, Uint64: value}
   193  }
   194  
   195  // Uint8 is used to represent a uint8 that may be null
   196  type Uint8 struct {
   197  	Valid bool
   198  	Uint8 uint8
   199  }
   200  
   201  // NewUint8 turns a uint8 into a valid null.Uint8
   202  func NewUint8(value uint8) Uint8 {
   203  	return Uint8{Valid: true, Uint8: value}
   204  }