From 934b5a1256f420f4a416d17e579e607d70162a5b Mon Sep 17 00:00:00 2001 From: aponos <167663542+aponos@users.noreply.github.com> Date: Sun, 25 Aug 2024 02:22:29 +0000 Subject: [PATCH 1/2] feat: add binary codec for scalajs platform This module includes a codec for the type UInt8Array. --- .../src/main/scala/codec/BinaryCodecs.scala | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 modules/core/js/src/main/scala/codec/BinaryCodecs.scala diff --git a/modules/core/js/src/main/scala/codec/BinaryCodecs.scala b/modules/core/js/src/main/scala/codec/BinaryCodecs.scala new file mode 100644 index 00000000..efef976d --- /dev/null +++ b/modules/core/js/src/main/scala/codec/BinaryCodecs.scala @@ -0,0 +1,23 @@ +// Copyright (c) 2018-2024 by Rob Norris and Contributors +// This software is licensed under the MIT License (MIT). +// For more information see LICENSE or https://opensource.org/licenses/MIT + +package skunk +package scalajs.codec + +import scodec.bits.ByteVector +import skunk.data.Type +import scala.scalajs.js.typedarray.Uint8Array + +trait BinaryCodecs { + + val uint8array = Codec.simple[Uint8Array]( + "\\x" + ByteVector.view(_).toHex, + hex => ByteVector.fromHex(hex.substring(2)).map(_.toUint8Array).toRight("Cannot decode bytes from HEX String"), + Type.bytea + ) + + +} + +object binary extends BinaryCodecs From 6f9aac29d3b27f18e1f8501f2311a9f830c49da3 Mon Sep 17 00:00:00 2001 From: aponos <167663542+aponos@users.noreply.github.com> Date: Sun, 25 Aug 2024 02:23:37 +0000 Subject: [PATCH 2/2] feat: add all codecs object --- modules/core/js/src/main/scala/codec/AllCodecs.scala | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 modules/core/js/src/main/scala/codec/AllCodecs.scala diff --git a/modules/core/js/src/main/scala/codec/AllCodecs.scala b/modules/core/js/src/main/scala/codec/AllCodecs.scala new file mode 100644 index 00000000..0a8b0151 --- /dev/null +++ b/modules/core/js/src/main/scala/codec/AllCodecs.scala @@ -0,0 +1,9 @@ +// Copyright (c) 2018-2024 by Rob Norris and Contributors +// This software is licensed under the MIT License (MIT). +// For more information see LICENSE or https://opensource.org/licenses/MIT + +package skunk.scalajs.codec + +trait AllCodecs extends BinaryCodecs + +object all extends AllCodecs