snapshot of https://github.com/pion/webrtc.git (main, 2026-09-15; blobs > 131072B omitted)
Some checks failed
REUSE Compliance Check / lint (push) Failing after 0s
Browser E2E / Test (push) Failing after 3s
Test / test (1.24) (push) Failing after 0s
Test / test-i386 (1.25) (push) Failing after 0s
Test / test-i386 (1.24) (push) Failing after 0s
Test / test-windows (1.25) (push) Failing after 0s
Test / test-windows (1.24) (push) Failing after 0s
Test / test (1.25) (push) Failing after 0s
Examples Tests / Test (push) Failing after 3s
Test / test-macos (1.25) (push) Failing after 0s
Test / test-macos (1.24) (push) Failing after 0s
Go mod tidy / tidy (push) Failing after 0s
Test / test-wasm (push) Failing after 0s
CodeQL / analyze (push) Failing after 1s
Fuzz / fuzz (push) Failing after 0s
Some checks failed
REUSE Compliance Check / lint (push) Failing after 0s
Browser E2E / Test (push) Failing after 3s
Test / test (1.24) (push) Failing after 0s
Test / test-i386 (1.25) (push) Failing after 0s
Test / test-i386 (1.24) (push) Failing after 0s
Test / test-windows (1.25) (push) Failing after 0s
Test / test-windows (1.24) (push) Failing after 0s
Test / test (1.25) (push) Failing after 0s
Examples Tests / Test (push) Failing after 3s
Test / test-macos (1.25) (push) Failing after 0s
Test / test-macos (1.24) (push) Failing after 0s
Go mod tidy / tidy (push) Failing after 0s
Test / test-wasm (push) Failing after 0s
CodeQL / analyze (push) Failing after 1s
Fuzz / fuzz (push) Failing after 0s
This commit is contained in:
204
pkg/null/null.go
Normal file
204
pkg/null/null.go
Normal file
@@ -0,0 +1,204 @@
|
||||
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// Package null is used to represent values where the 0 value is significant
|
||||
// This pattern is common in ECMAScript, this allows us to maintain a matching API
|
||||
package null
|
||||
|
||||
// Bool is used to represent a bool that may be null.
|
||||
type Bool struct {
|
||||
Valid bool
|
||||
Bool bool
|
||||
}
|
||||
|
||||
// NewBool turns a bool into a valid null.Bool.
|
||||
func NewBool(value bool) Bool {
|
||||
return Bool{Valid: true, Bool: value}
|
||||
}
|
||||
|
||||
// Byte is used to represent a byte that may be null.
|
||||
type Byte struct {
|
||||
Valid bool
|
||||
Byte byte
|
||||
}
|
||||
|
||||
// NewByte turns a byte into a valid null.Byte.
|
||||
func NewByte(value byte) Byte {
|
||||
return Byte{Valid: true, Byte: value}
|
||||
}
|
||||
|
||||
// Complex128 is used to represent a complex128 that may be null.
|
||||
type Complex128 struct {
|
||||
Valid bool
|
||||
Complex128 complex128
|
||||
}
|
||||
|
||||
// NewComplex128 turns a complex128 into a valid null.Complex128.
|
||||
func NewComplex128(value complex128) Complex128 {
|
||||
return Complex128{Valid: true, Complex128: value}
|
||||
}
|
||||
|
||||
// Complex64 is used to represent a complex64 that may be null.
|
||||
type Complex64 struct {
|
||||
Valid bool
|
||||
Complex64 complex64
|
||||
}
|
||||
|
||||
// NewComplex64 turns a complex64 into a valid null.Complex64.
|
||||
func NewComplex64(value complex64) Complex64 {
|
||||
return Complex64{Valid: true, Complex64: value}
|
||||
}
|
||||
|
||||
// Float32 is used to represent a float32 that may be null.
|
||||
type Float32 struct {
|
||||
Valid bool
|
||||
Float32 float32
|
||||
}
|
||||
|
||||
// NewFloat32 turns a float32 into a valid null.Float32.
|
||||
func NewFloat32(value float32) Float32 {
|
||||
return Float32{Valid: true, Float32: value}
|
||||
}
|
||||
|
||||
// Float64 is used to represent a float64 that may be null.
|
||||
type Float64 struct {
|
||||
Valid bool
|
||||
Float64 float64
|
||||
}
|
||||
|
||||
// NewFloat64 turns a float64 into a valid null.Float64.
|
||||
func NewFloat64(value float64) Float64 {
|
||||
return Float64{Valid: true, Float64: value}
|
||||
}
|
||||
|
||||
// Int is used to represent a int that may be null.
|
||||
type Int struct {
|
||||
Valid bool
|
||||
Int int
|
||||
}
|
||||
|
||||
// NewInt turns a int into a valid null.Int.
|
||||
func NewInt(value int) Int {
|
||||
return Int{Valid: true, Int: value}
|
||||
}
|
||||
|
||||
// Int16 is used to represent a int16 that may be null.
|
||||
type Int16 struct {
|
||||
Valid bool
|
||||
Int16 int16
|
||||
}
|
||||
|
||||
// NewInt16 turns a int16 into a valid null.Int16.
|
||||
func NewInt16(value int16) Int16 {
|
||||
return Int16{Valid: true, Int16: value}
|
||||
}
|
||||
|
||||
// Int32 is used to represent a int32 that may be null.
|
||||
type Int32 struct {
|
||||
Valid bool
|
||||
Int32 int32
|
||||
}
|
||||
|
||||
// NewInt32 turns a int32 into a valid null.Int32.
|
||||
func NewInt32(value int32) Int32 {
|
||||
return Int32{Valid: true, Int32: value}
|
||||
}
|
||||
|
||||
// Int64 is used to represent a int64 that may be null.
|
||||
type Int64 struct {
|
||||
Valid bool
|
||||
Int64 int64
|
||||
}
|
||||
|
||||
// NewInt64 turns a int64 into a valid null.Int64.
|
||||
func NewInt64(value int64) Int64 {
|
||||
return Int64{Valid: true, Int64: value}
|
||||
}
|
||||
|
||||
// Int8 is used to represent a int8 that may be null.
|
||||
type Int8 struct {
|
||||
Valid bool
|
||||
Int8 int8
|
||||
}
|
||||
|
||||
// NewInt8 turns a int8 into a valid null.Int8.
|
||||
func NewInt8(value int8) Int8 {
|
||||
return Int8{Valid: true, Int8: value}
|
||||
}
|
||||
|
||||
// Rune is used to represent a rune that may be null.
|
||||
type Rune struct {
|
||||
Valid bool
|
||||
Rune rune
|
||||
}
|
||||
|
||||
// NewRune turns a rune into a valid null.Rune.
|
||||
func NewRune(value rune) Rune {
|
||||
return Rune{Valid: true, Rune: value}
|
||||
}
|
||||
|
||||
// String is used to represent a string that may be null.
|
||||
type String struct {
|
||||
Valid bool
|
||||
String string
|
||||
}
|
||||
|
||||
// NewString turns a string into a valid null.String.
|
||||
func NewString(value string) String {
|
||||
return String{Valid: true, String: value}
|
||||
}
|
||||
|
||||
// Uint is used to represent a uint that may be null.
|
||||
type Uint struct {
|
||||
Valid bool
|
||||
Uint uint
|
||||
}
|
||||
|
||||
// NewUint turns a uint into a valid null.Uint.
|
||||
func NewUint(value uint) Uint {
|
||||
return Uint{Valid: true, Uint: value}
|
||||
}
|
||||
|
||||
// Uint16 is used to represent a uint16 that may be null.
|
||||
type Uint16 struct {
|
||||
Valid bool
|
||||
Uint16 uint16
|
||||
}
|
||||
|
||||
// NewUint16 turns a uint16 into a valid null.Uint16.
|
||||
func NewUint16(value uint16) Uint16 {
|
||||
return Uint16{Valid: true, Uint16: value}
|
||||
}
|
||||
|
||||
// Uint32 is used to represent a uint32 that may be null.
|
||||
type Uint32 struct {
|
||||
Valid bool
|
||||
Uint32 uint32
|
||||
}
|
||||
|
||||
// NewUint32 turns a uint32 into a valid null.Uint32.
|
||||
func NewUint32(value uint32) Uint32 {
|
||||
return Uint32{Valid: true, Uint32: value}
|
||||
}
|
||||
|
||||
// Uint64 is used to represent a uint64 that may be null.
|
||||
type Uint64 struct {
|
||||
Valid bool
|
||||
Uint64 uint64
|
||||
}
|
||||
|
||||
// NewUint64 turns a uint64 into a valid null.Uint64.
|
||||
func NewUint64(value uint64) Uint64 {
|
||||
return Uint64{Valid: true, Uint64: value}
|
||||
}
|
||||
|
||||
// Uint8 is used to represent a uint8 that may be null.
|
||||
type Uint8 struct {
|
||||
Valid bool
|
||||
Uint8 uint8
|
||||
}
|
||||
|
||||
// NewUint8 turns a uint8 into a valid null.Uint8.
|
||||
func NewUint8(value uint8) Uint8 {
|
||||
return Uint8{Valid: true, Uint8: value}
|
||||
}
|
||||
316
pkg/null/null_test.go
Normal file
316
pkg/null/null_test.go
Normal file
@@ -0,0 +1,316 @@
|
||||
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package null
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewBool(t *testing.T) {
|
||||
value := bool(true)
|
||||
nullable := NewBool(value)
|
||||
|
||||
assert.Equal(t,
|
||||
true,
|
||||
nullable.Valid,
|
||||
"valid: Bool",
|
||||
)
|
||||
|
||||
assert.Equal(t,
|
||||
value,
|
||||
nullable.Bool,
|
||||
"value: Bool",
|
||||
)
|
||||
}
|
||||
|
||||
func TestNewByte(t *testing.T) {
|
||||
value := byte('a')
|
||||
nullable := NewByte(value)
|
||||
|
||||
assert.Equal(t,
|
||||
true,
|
||||
nullable.Valid,
|
||||
"valid: Byte",
|
||||
)
|
||||
|
||||
assert.Equal(t,
|
||||
value,
|
||||
nullable.Byte,
|
||||
"value: Byte",
|
||||
)
|
||||
}
|
||||
|
||||
func TestNewComplex128(t *testing.T) {
|
||||
value := complex128(-5 + 12i)
|
||||
nullable := NewComplex128(value)
|
||||
|
||||
assert.Equal(t,
|
||||
true,
|
||||
nullable.Valid,
|
||||
"valid: Complex128",
|
||||
)
|
||||
|
||||
assert.Equal(t,
|
||||
value,
|
||||
nullable.Complex128,
|
||||
"value: Complex128",
|
||||
)
|
||||
}
|
||||
|
||||
func TestNewComplex64(t *testing.T) {
|
||||
value := complex64(-5 + 12i)
|
||||
nullable := NewComplex64(value)
|
||||
|
||||
assert.Equal(t,
|
||||
true,
|
||||
nullable.Valid,
|
||||
"valid: Complex64",
|
||||
)
|
||||
|
||||
assert.Equal(t,
|
||||
value,
|
||||
nullable.Complex64,
|
||||
"value: Complex64",
|
||||
)
|
||||
}
|
||||
|
||||
func TestNewFloat32(t *testing.T) {
|
||||
value := float32(0.5)
|
||||
nullable := NewFloat32(value)
|
||||
|
||||
assert.Equal(t,
|
||||
true,
|
||||
nullable.Valid,
|
||||
"valid: Float32",
|
||||
)
|
||||
|
||||
assert.Equal(t,
|
||||
value,
|
||||
nullable.Float32,
|
||||
"value: Float32",
|
||||
)
|
||||
}
|
||||
|
||||
func TestNewFloat64(t *testing.T) {
|
||||
value := float64(0.5)
|
||||
nullable := NewFloat64(value)
|
||||
|
||||
assert.Equal(t,
|
||||
true,
|
||||
nullable.Valid,
|
||||
"valid: Float64",
|
||||
)
|
||||
|
||||
assert.Equal(t,
|
||||
value,
|
||||
nullable.Float64,
|
||||
"value: Float64",
|
||||
)
|
||||
}
|
||||
|
||||
func TestNewInt(t *testing.T) {
|
||||
value := int(1)
|
||||
nullable := NewInt(value)
|
||||
|
||||
assert.Equal(t,
|
||||
true,
|
||||
nullable.Valid,
|
||||
"valid: Int",
|
||||
)
|
||||
|
||||
assert.Equal(t,
|
||||
value,
|
||||
nullable.Int,
|
||||
"value: Int",
|
||||
)
|
||||
}
|
||||
|
||||
func TestNewInt16(t *testing.T) {
|
||||
value := int16(1)
|
||||
nullable := NewInt16(value)
|
||||
|
||||
assert.Equal(t,
|
||||
true,
|
||||
nullable.Valid,
|
||||
"valid: Int16",
|
||||
)
|
||||
|
||||
assert.Equal(t,
|
||||
value,
|
||||
nullable.Int16,
|
||||
"value: Int16",
|
||||
)
|
||||
}
|
||||
|
||||
func TestNewInt32(t *testing.T) {
|
||||
value := int32(1)
|
||||
nullable := NewInt32(value)
|
||||
|
||||
assert.Equal(t,
|
||||
true,
|
||||
nullable.Valid,
|
||||
"valid: Int32",
|
||||
)
|
||||
|
||||
assert.Equal(t,
|
||||
value,
|
||||
nullable.Int32,
|
||||
"value: Int32",
|
||||
)
|
||||
}
|
||||
|
||||
func TestNewInt64(t *testing.T) {
|
||||
value := int64(1)
|
||||
nullable := NewInt64(value)
|
||||
|
||||
assert.Equal(t,
|
||||
true,
|
||||
nullable.Valid,
|
||||
"valid: Int64",
|
||||
)
|
||||
|
||||
assert.Equal(t,
|
||||
value,
|
||||
nullable.Int64,
|
||||
"value: Int64",
|
||||
)
|
||||
}
|
||||
|
||||
func TestNewInt8(t *testing.T) {
|
||||
value := int8(1)
|
||||
nullable := NewInt8(value)
|
||||
|
||||
assert.Equal(t,
|
||||
true,
|
||||
nullable.Valid,
|
||||
"valid: Int8",
|
||||
)
|
||||
|
||||
assert.Equal(t,
|
||||
value,
|
||||
nullable.Int8,
|
||||
"value: Int8",
|
||||
)
|
||||
}
|
||||
|
||||
func TestNewRune(t *testing.T) {
|
||||
value := rune('p')
|
||||
nullable := NewRune(value)
|
||||
|
||||
assert.Equal(t,
|
||||
true,
|
||||
nullable.Valid,
|
||||
"valid: Rune",
|
||||
)
|
||||
|
||||
assert.Equal(t,
|
||||
value,
|
||||
nullable.Rune,
|
||||
"value: Rune",
|
||||
)
|
||||
}
|
||||
|
||||
func TestNewString(t *testing.T) {
|
||||
value := string("pion")
|
||||
nullable := NewString(value)
|
||||
|
||||
assert.Equal(t,
|
||||
true,
|
||||
nullable.Valid,
|
||||
"valid: String",
|
||||
)
|
||||
|
||||
assert.Equal(t,
|
||||
value,
|
||||
nullable.String,
|
||||
"value: String",
|
||||
)
|
||||
}
|
||||
|
||||
func TestNewUint(t *testing.T) {
|
||||
value := uint(1)
|
||||
nullable := NewUint(value)
|
||||
|
||||
assert.Equal(t,
|
||||
true,
|
||||
nullable.Valid,
|
||||
"valid: Uint",
|
||||
)
|
||||
|
||||
assert.Equal(t,
|
||||
value,
|
||||
nullable.Uint,
|
||||
"value: Uint",
|
||||
)
|
||||
}
|
||||
|
||||
func TestNewUint16(t *testing.T) {
|
||||
value := uint16(1)
|
||||
nullable := NewUint16(value)
|
||||
|
||||
assert.Equal(t,
|
||||
true,
|
||||
nullable.Valid,
|
||||
"valid: Uint16",
|
||||
)
|
||||
|
||||
assert.Equal(t,
|
||||
value,
|
||||
nullable.Uint16,
|
||||
"value: Uint16",
|
||||
)
|
||||
}
|
||||
|
||||
func TestNewUint32(t *testing.T) {
|
||||
value := uint32(1)
|
||||
nullable := NewUint32(value)
|
||||
|
||||
assert.Equal(t,
|
||||
true,
|
||||
nullable.Valid,
|
||||
"valid: Uint32",
|
||||
)
|
||||
|
||||
assert.Equal(t,
|
||||
value,
|
||||
nullable.Uint32,
|
||||
"value: Uint32",
|
||||
)
|
||||
}
|
||||
|
||||
func TestNewUint64(t *testing.T) {
|
||||
value := uint64(1)
|
||||
nullable := NewUint64(value)
|
||||
|
||||
assert.Equal(t,
|
||||
true,
|
||||
nullable.Valid,
|
||||
"valid: Uint64",
|
||||
)
|
||||
|
||||
assert.Equal(t,
|
||||
value,
|
||||
nullable.Uint64,
|
||||
"value: Uint64",
|
||||
)
|
||||
}
|
||||
|
||||
func TestNewUint8(t *testing.T) {
|
||||
value := uint8(1)
|
||||
nullable := NewUint8(value)
|
||||
|
||||
assert.Equal(t,
|
||||
true,
|
||||
nullable.Valid,
|
||||
"valid: Uint8",
|
||||
)
|
||||
|
||||
assert.Equal(t,
|
||||
value,
|
||||
nullable.Uint8,
|
||||
"value: Uint8",
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user