From ded1681dc5f69cab12e6420f3dc75482d73e07c4 Mon Sep 17 00:00:00 2001 From: Cathode Cube <12895141+ramon54321@users.noreply.github.com> Date: Sun, 21 Jul 2024 09:31:45 -0400 Subject: [PATCH] Add Float32 and Float64 to Msg conversions --- upack/src/upack/Msg.scala | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/upack/src/upack/Msg.scala b/upack/src/upack/Msg.scala index cb674b57d..66a246484 100644 --- a/upack/src/upack/Msg.scala +++ b/upack/src/upack/Msg.scala @@ -73,6 +73,24 @@ sealed trait Msg extends Readable with geny.Writable{ case UInt64(value) => value case _ => throw Msg.InvalidData(this, "Expected ujson.Num") } + /** + * Returns the `Float` value of this [[Msg]], fails if it is not + * a [[upack.Float32]] or [[upack.Float64]] + */ + def float32 = this match{ + case Float32(value) => value + case Float64(value) => value.toFloat + case _ => throw Msg.InvalidData(this, "Expected ujson.Num") + } + /** + * Returns the `Double` value of this [[Msg]], fails if it is not + * a [[upack.Float32]] or [[upack.Float64]] + */ + def float64 = this match{ + case Float32(value) => value.toDouble + case Float64(value) => value + case _ => throw Msg.InvalidData(this, "Expected ujson.Num") + } /** * Returns the `Boolean` value of this [[Msg]], fails if it is not * a [[upack.Bool]]