aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/direct_bt/DBGattServer.hpp11
-rw-r--r--java/org/direct_bt/DBGattValue.java8
2 files changed, 19 insertions, 0 deletions
diff --git a/api/direct_bt/DBGattServer.hpp b/api/direct_bt/DBGattServer.hpp
index d32de77a..d24f34df 100644
--- a/api/direct_bt/DBGattServer.hpp
+++ b/api/direct_bt/DBGattServer.hpp
@@ -535,6 +535,17 @@ namespace direct_bt {
return jau::POctets(sourcelist, jau::endian::little);
}
+ /** Convenience jau::POctets ctor function to create DBGattChar or DBGattDesc values. */
+ inline jau::POctets make_gvalue(const jau::nsize_t capacity, const jau::nsize_t size, std::initializer_list<uint8_t> sourcelist) {
+ jau::POctets p(capacity, size, jau::endian::little);
+ p.bzero();
+ const jau::nsize_t max_size = std::min(size, sourcelist.size());
+ if( 0 < max_size ) {
+ std::memcpy(p.get_wptr(), sourcelist.begin(), max_size);
+ }
+ return p;
+ }
+
/**
* Representing a Gatt Service object from the ::GATTRole::Server perspective.
*
diff --git a/java/org/direct_bt/DBGattValue.java b/java/org/direct_bt/DBGattValue.java
index b695c5cd..070ee7b4 100644
--- a/java/org/direct_bt/DBGattValue.java
+++ b/java/org/direct_bt/DBGattValue.java
@@ -76,6 +76,14 @@ public class DBGattValue
return new DBGattValue(p, p.length);
}
+ /** Convenience {@link DBGattValue} ctor function. */
+ public static DBGattValue make(final int capacity, final int size, final byte[] s) {
+ final byte[] p = new byte[size];
+ final int max_size = Math.min(size, s.length);
+ System.arraycopy(s, 0, p, 0, max_size);
+ return new DBGattValue(p, capacity, true /* variable_length */);
+ }
+
/**
* Constructor
* @param value the data, which length defines the maximum writable fixed length if variable length is false.