pkubaj commented on code in PR #3696:
URL: https://github.com/apache/brpc/pull/3696#discussion_r4443300245


##########
src/brpc/mongo_head.h:
##########
@@ -62,12 +62,12 @@ struct mongo_head_t {
     int32_t op_code;         // request type, see MongoOpCode.
 
     void make_host_endian() {
-        if (!ARCH_CPU_LITTLE_ENDIAN) {
-            message_length = butil::ByteSwap((uint32_t)message_length);
-            request_id = butil::ByteSwap((uint32_t)request_id);
-            response_to = butil::ByteSwap((uint32_t)response_to);
-            op_code = butil::ByteSwap((uint32_t)op_code);
-        }
+#if !defined(ARCH_CPU_LITTLE_ENDIAN)
+        message_length = butil::ByteSwap((uint32_t)message_length);
+        request_id = butil::ByteSwap((uint32_t)request_id);
+        response_to = butil::ByteSwap((uint32_t)response_to);
+        op_code = butil::ByteSwap((uint32_t)op_code);

Review Comment:
   Fixed in 410f2753f282: `ProcessMongoRequest()` now converts the header to 
host order, `SendMongoResponse()` writes the header and the four integers after 
it in little-endian order (`mongo_head_t::make_wire_endian()`, 
`butil::ByteSwapToLE32/64`), and the `SerializeError()` doc says adaptors must 
emit the wire format too. The unit test builds its headers through 
`make_wire_endian()`, reads the response back through `make_host_endian()`, 
checks the integers `SendMongoResponse()` writes, and gains 
`little_endian_wire_format`, fed the fixed bytes (including `d4 07 00 00`), 
which checks the op_code the service sees and the response bytes. Verified with 
brpc built on FreeBSD big-endian powerpc64: 6/6 pass; against the previous 
`mongo_protocol.cpp` the same tests fail the way you describe (service never 
invoked, error reply on the wire).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to