1919#include < string_view>
2020#include < vector>
2121
22+ #include " include/proxy-wasm/exports.h"
2223#include " include/proxy-wasm/limits.h"
2324#include " include/proxy-wasm/word.h"
2425
@@ -45,7 +46,10 @@ bool PairsUtil::marshalPairs(const Pairs &pairs, char *buffer, size_t size) {
4546 const char *end = buffer + size;
4647
4748 // Write number of pairs.
48- uint32_t num_pairs = htowasm (pairs.size ());
49+ uint32_t num_pairs =
50+ htowasm (pairs.size (), contextOrEffectiveContext () != nullptr
51+ ? contextOrEffectiveContext ()->wasmVm ()->usesWasmByteOrder ()
52+ : false );
4953 if (pos + sizeof (uint32_t ) > end) {
5054 return false ;
5155 }
@@ -54,15 +58,21 @@ bool PairsUtil::marshalPairs(const Pairs &pairs, char *buffer, size_t size) {
5458
5559 for (const auto &p : pairs) {
5660 // Write name length.
57- uint32_t name_len = htowasm (p.first .size ());
61+ uint32_t name_len =
62+ htowasm (p.first .size (), contextOrEffectiveContext () != nullptr
63+ ? contextOrEffectiveContext ()->wasmVm ()->usesWasmByteOrder ()
64+ : false );
5865 if (pos + sizeof (uint32_t ) > end) {
5966 return false ;
6067 }
6168 ::memcpy (pos, &name_len, sizeof (uint32_t ));
6269 pos += sizeof (uint32_t );
6370
6471 // Write value length.
65- uint32_t value_len = htowasm (p.second .size ());
72+ uint32_t value_len =
73+ htowasm (p.second .size (), contextOrEffectiveContext () != nullptr
74+ ? contextOrEffectiveContext ()->wasmVm ()->usesWasmByteOrder ()
75+ : false );
6676 if (pos + sizeof (uint32_t ) > end) {
6777 return false ;
6878 }
@@ -103,7 +113,10 @@ Pairs PairsUtil::toPairs(std::string_view buffer) {
103113 if (pos + sizeof (uint32_t ) > end) {
104114 return {};
105115 }
106- uint32_t num_pairs = wasmtoh (*reinterpret_cast <const uint32_t *>(pos));
116+ uint32_t num_pairs = wasmtoh (*reinterpret_cast <const uint32_t *>(pos),
117+ contextOrEffectiveContext () != nullptr
118+ ? contextOrEffectiveContext ()->wasmVm ()->usesWasmByteOrder ()
119+ : false );
107120 pos += sizeof (uint32_t );
108121
109122 // Check if we're not going to exceed the limit.
@@ -122,14 +135,20 @@ Pairs PairsUtil::toPairs(std::string_view buffer) {
122135 if (pos + sizeof (uint32_t ) > end) {
123136 return {};
124137 }
125- s.first = wasmtoh (*reinterpret_cast <const uint32_t *>(pos));
138+ s.first = wasmtoh (*reinterpret_cast <const uint32_t *>(pos),
139+ contextOrEffectiveContext () != nullptr
140+ ? contextOrEffectiveContext ()->wasmVm ()->usesWasmByteOrder ()
141+ : false );
126142 pos += sizeof (uint32_t );
127143
128144 // Read value length.
129145 if (pos + sizeof (uint32_t ) > end) {
130146 return {};
131147 }
132- s.second = wasmtoh (*reinterpret_cast <const uint32_t *>(pos));
148+ s.second = wasmtoh (*reinterpret_cast <const uint32_t *>(pos),
149+ contextOrEffectiveContext () != nullptr
150+ ? contextOrEffectiveContext ()->wasmVm ()->usesWasmByteOrder ()
151+ : false );
133152 pos += sizeof (uint32_t );
134153 }
135154
0 commit comments