@@ -68,7 +68,8 @@ std::optional<std::string> maybeNonemptyString(Napi::Value x, const std::string&
6868
6969// If the object is null/undef/empty returns nullopt, otherwise if a Uint8Array returns a
7070// std::vector<unsigned char> of the value. Throws if something else.
71- std::optional<std::vector<unsigned char >> maybeNonemptyBuffer (Napi::Value x, const std::string& identifier);
71+ std::optional<std::vector<unsigned char >> maybeNonemptyBuffer (
72+ Napi::Value x, const std::string& identifier);
7273
7374// Implementation struct of toJs(); we add specializations of this for any C++ types we want to be
7475// able to convert into JS types.
@@ -121,14 +122,24 @@ struct toJs_impl<T, std::enable_if_t<std::is_convertible_v<T, std::string_view>>
121122};
122123
123124template <typename T>
124- struct toJs_impl <T, std::enable_if_t <
125- std::is_convertible_v<T, std::span<const unsigned char >> &&
126- !std::is_same_v<std::remove_cv_t <T>, std::vector<unsigned char >>>> {
125+ struct toJs_impl <
126+ T,
127+ std::enable_if_t <
128+ std::is_convertible_v<T, std::span<const unsigned char >> &&
129+ !std::is_same_v<std::remove_cv_t <T>, std::vector<unsigned char >>>> {
127130 auto operator ()(const Napi::Env& env, std::span<const unsigned char > b) const {
128131 return Napi::Buffer<uint8_t >::Copy (env, b.data (), b.size ());
129132 }
130133};
131134
135+ // this wrap std::vector<unsigned char> to Uint8array in the js world
136+ template <>
137+ struct toJs_impl <std::vector<unsigned char >> {
138+ auto operator ()(const Napi::Env& env, std::vector<unsigned char > b) const {
139+ return Napi::Buffer<uint8_t >::Copy (env, b.data (), b.size ());
140+ }
141+ };
142+
132143template <typename T>
133144struct toJs_impl <T, std::enable_if_t <std::is_base_of_v<Napi::Value, T>>> {
134145 auto operator ()(const Napi::Env& env, const T& val) { return val; }
0 commit comments