From d48cbe75ef29a9c67c9d176bf58e56ea6448fb9e Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 21 Oct 2024 20:23:36 +0200 Subject: IMP: Major refactor of header and source files extensions. Signed-off-by: Amlal El Mahrouss --- dev/zka/src/GUIDWizard.cc | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 dev/zka/src/GUIDWizard.cc (limited to 'dev/zka/src/GUIDWizard.cc') diff --git a/dev/zka/src/GUIDWizard.cc b/dev/zka/src/GUIDWizard.cc new file mode 100644 index 00000000..77635979 --- /dev/null +++ b/dev/zka/src/GUIDWizard.cc @@ -0,0 +1,72 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + + File: GUIDWizard.cxx + Purpose: GUID helper code + + Revision History: + +------------------------------------------- */ + +#include +#include + +// begin of ascii 'readable' characters. (A, C, C, 1, 2) +#define kAsciiBegin 47 +// @brief Size of UUID. +#define kUUIDSize 37 + +namespace Kernel::XRN::Version1 +{ + auto cf_make_sequence(const ArrayList& uuidSeq) -> Ref + { + GUIDSequence* seq = new GUIDSequence(); + MUST_PASS(seq); + + Ref seq_ref{*seq}; + + seq_ref.Leak().fMs1 = uuidSeq[0]; + seq_ref.Leak().fMs2 = uuidSeq[1]; + seq_ref.Leak().fMs3 = uuidSeq[2]; + seq_ref.Leak().fMs4[0] = uuidSeq[3]; + seq_ref.Leak().fMs4[1] = uuidSeq[4]; + seq_ref.Leak().fMs4[2] = uuidSeq[5]; + seq_ref.Leak().fMs4[3] = uuidSeq[6]; + seq_ref.Leak().fMs4[4] = uuidSeq[7]; + seq_ref.Leak().fMs4[5] = uuidSeq[8]; + seq_ref.Leak().fMs4[6] = uuidSeq[9]; + seq_ref.Leak().fMs4[7] = uuidSeq[10]; + + return seq_ref; + } + + // @brief Tries to make a guid out of a string. + // This function is not complete for now + auto cf_try_guid_to_string(Ref& seq) -> ErrorOr> + { + Char buf[kUUIDSize]; + + for (SizeT index = 0; index < 16; ++index) + { + buf[index] = seq.Leak().u8[index] + kAsciiBegin; + } + + for (SizeT index = 16; index < 24; ++index) + { + buf[index] = seq.Leak().u16[index] + kAsciiBegin; + } + + for (SizeT index = 24; index < 28; ++index) + { + buf[index] = seq.Leak().u32[index] + kAsciiBegin; + } + + auto view = StringBuilder::Construct(buf); + + if (view) + return ErrorOr>{view.Leak()}; + + return ErrorOr>{-1}; + } +} // namespace Kernel::XRN::Version1 -- cgit v1.2.3