issuu / ocaml-protoc-plugin

ocaml-protoc-plugin
https://issuu.github.io/ocaml-protoc-plugin/
Other
48 stars 19 forks source link

Fixed precision / floating point fields fails on BigEndian architectures. #36

Closed andersfugmann closed 1 year ago

andersfugmann commented 1 year ago

When testing on s390x architecture floating point tests fails. I assume that this is because fixed fields are sent in native endian (or maybe big endian conversion is just plain wrong).

The current code has a custom implementation of endian conversion functions, but similar exists in Bytes since 4.08 so these should be safe to use.

The error observed on s390x (64 bit big endian platform):

# File "test/repeated_test.ml", line 1, characters 0-0:
# /usr/bin/git --no-pager diff --no-index --color=always -u _build/default/test/repeated_test.ml _build/default/test/repeated_test.ml.corrected
# diff --git a/_build/default/test/repeated_test.ml b/_build/default/test/repeated_test.ml.corrected
# index cbc2d48..f74bb25 100644
# --- a/_build/default/test/repeated_test.ml
# +++ b/_build/default/test/repeated_test.ml.corrected
# @@ -17,10 +17,10 @@ let%expect_test _ =
#    Test_lib.test_encode (module T) t;
#    [%expect {|
#      i: 0
# -    i: 1
# -    i: 2
# -    i: 3
# -    i: 4 |}]
# +    i: 3.03865194161742e-319
# +    i: 3.16202013338398e-322
# +    i: 1.04346664401671e-320
# +    i: 2.05531308669959e-320 |}]
#  
#  let%expect_test _ =
#    let module T = Repeated.Float in
# @@ -28,10 +28,10 @@ let%expect_test _ =
#    Test_lib.test_encode (module T) t;
#    [%expect {|
#      i: 0
# -    i: 1
# -    i: 2
# -    i: 3
# -    i: 4 |}]
# +    i: 4.60060299e-41
# +    i: 8.96831017e-44
# +    i: 2.30485571e-41
# +    i: 4.60074312e-41 |}]
#  
#  let%expect_test _ =
#    let module T = Repeated.String in