Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vectorFromGVariantByteArray in Utils #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,14 @@ std::string Utils::stringFromGVariantByteArray(const GVariant *pVariant)
return array.data();
}

// Extracts a VECTOR from an array of bytes ("ay")
std::vector<guint8> Utils::vectorFromGVariantByteArray(const GVariant *pVariant)
{
gsize size;
gconstpointer pPtr = g_variant_get_fixed_array(const_cast<GVariant *>(pVariant), &size, 1);
std::vector<guint8> array(size + 1, 0);
memcpy(array.data(), pPtr, size);
return array;
}

}; // namespace ggk
3 changes: 3 additions & 0 deletions src/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ struct Utils
// Extracts a string from an array of bytes ("ay")
static std::string stringFromGVariantByteArray(const GVariant *pVariant);

// Extracts a VECTOR from an array of bytes ("ay")
static std::vector<guint8> vectorFromGVariantByteArray(const GVariant *pVariant);

// -----------------------------------------------------------------------------------------------------------------------------
// Endian conversion
//
Expand Down