Skip to content

Commit

Permalink
protocol/io.go: New OptionalFuncIO() method
Browse files Browse the repository at this point in the history
  • Loading branch information
TwistedAsylumMC committed Nov 19, 2023
1 parent 539a193 commit 2b48a19
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions minecraft/protocol/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ func OptionalFunc[T any](r IO, x *Optional[T], f func(*T)) any {
return x
}

// OptionalFuncIO reads/writes an Optional[T].
func OptionalFuncIO[T any](r IO, x *Optional[T], f func(IO, *T)) any {
r.Bool(&x.set)
if x.set {
f(r, &x.val)
}
return x
}

// OptionalMarshaler reads/writes an Optional assuming *T implements Marshaler.
func OptionalMarshaler[T any, A PtrMarshaler[T]](r IO, x *Optional[T]) {
r.Bool(&x.set)
Expand Down

0 comments on commit 2b48a19

Please sign in to comment.