mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 17:33:38 +00:00
Add predicates for reading multibyte integers from binary file streams. As
with the corresponding predicates for writing multibyte integers to binary file
streams, we provide versions for big-endian, little-endian and native byte
orders.
library/io.m:
Add a new type that represents possibly incomplete results when reading
from binary file streams.
Add the new predicates.
tests/hard_coded/Mmakefile:
tests/hard_coded/read_binary_{int,uint}{16,32,64}.{m,exp}:
Add tests of the new predicates.
109 lines
4.0 KiB
Plaintext
109 lines
4.0 KiB
Plaintext
================
|
|
Input: []
|
|
Result: EOF (read big-endian)
|
|
================
|
|
Input: [1u8]
|
|
Result: Incomplete ([1u8]) (read big-endian)
|
|
================
|
|
Input: [1u8, 2u8]
|
|
Result: Incomplete ([1u8, 2u8]) (read big-endian)
|
|
================
|
|
Input: [1u8, 2u8, 3u8]
|
|
Result: Incomplete ([1u8, 2u8, 3u8]) (read big-endian)
|
|
================
|
|
Input: [1u8, 2u8, 3u8, 4u8]
|
|
Result: Incomplete ([1u8, 2u8, 3u8, 4u8]) (read big-endian)
|
|
================
|
|
Input: [1u8, 2u8, 3u8, 4u8, 5u8]
|
|
Result: Incomplete ([1u8, 2u8, 3u8, 4u8, 5u8]) (read big-endian)
|
|
================
|
|
Input: [1u8, 2u8, 3u8, 4u8, 5u8, 6u8]
|
|
Result: Incomplete ([1u8, 2u8, 3u8, 4u8, 5u8, 6u8]) (read big-endian)
|
|
================
|
|
Input: [1u8, 2u8, 3u8, 4u8, 5u8, 7u8]
|
|
Result: Incomplete ([1u8, 2u8, 3u8, 4u8, 5u8, 7u8]) (read big-endian)
|
|
================
|
|
Input: [1u8, 2u8, 3u8, 4u8, 5u8, 7u8, 8u8]
|
|
Result: Incomplete ([1u8, 2u8, 3u8, 4u8, 5u8, 7u8, 8u8]) (read big-endian)
|
|
================
|
|
Input: [0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8] (LE: 72057594037927936) (BE: 1)
|
|
Result: 1i64 (read big-endian)
|
|
================
|
|
Input: [255u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8] (LE: 255) (BE: -72057594037927936)
|
|
Result: -72057594037927936i64 (read big-endian)
|
|
================
|
|
Input: [1u8, 1u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8] (LE: 257) (BE: 72339069014638592)
|
|
Result: 72339069014638592i64 (read big-endian)
|
|
================
|
|
Input: []
|
|
Result: EOF (read little-endian)
|
|
================
|
|
Input: [1u8]
|
|
Result: Incomplete ([1u8]) (read little-endian)
|
|
================
|
|
Input: [1u8, 2u8]
|
|
Result: Incomplete ([1u8, 2u8]) (read little-endian)
|
|
================
|
|
Input: [1u8, 2u8, 3u8]
|
|
Result: Incomplete ([1u8, 2u8, 3u8]) (read little-endian)
|
|
================
|
|
Input: [1u8, 2u8, 3u8, 4u8]
|
|
Result: Incomplete ([1u8, 2u8, 3u8, 4u8]) (read little-endian)
|
|
================
|
|
Input: [1u8, 2u8, 3u8, 4u8, 5u8]
|
|
Result: Incomplete ([1u8, 2u8, 3u8, 4u8, 5u8]) (read little-endian)
|
|
================
|
|
Input: [1u8, 2u8, 3u8, 4u8, 5u8, 6u8]
|
|
Result: Incomplete ([1u8, 2u8, 3u8, 4u8, 5u8, 6u8]) (read little-endian)
|
|
================
|
|
Input: [1u8, 2u8, 3u8, 4u8, 5u8, 7u8]
|
|
Result: Incomplete ([1u8, 2u8, 3u8, 4u8, 5u8, 7u8]) (read little-endian)
|
|
================
|
|
Input: [1u8, 2u8, 3u8, 4u8, 5u8, 7u8, 8u8]
|
|
Result: Incomplete ([1u8, 2u8, 3u8, 4u8, 5u8, 7u8, 8u8]) (read little-endian)
|
|
================
|
|
Input: [0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8] (LE: 72057594037927936) (BE: 1)
|
|
Result: 72057594037927936i64 (read little-endian)
|
|
================
|
|
Input: [255u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8] (LE: 255) (BE: -72057594037927936)
|
|
Result: 255i64 (read little-endian)
|
|
================
|
|
Input: [1u8, 1u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8] (LE: 257) (BE: 72339069014638592)
|
|
Result: 257i64 (read little-endian)
|
|
================
|
|
Input: []
|
|
Result: EOF (read native byte order)
|
|
================
|
|
Input: [1u8]
|
|
Result: Incomplete ([1u8]) (read native byte order)
|
|
================
|
|
Input: [1u8, 2u8]
|
|
Result: Incomplete ([1u8, 2u8]) (read native byte order)
|
|
================
|
|
Input: [1u8, 2u8, 3u8]
|
|
Result: Incomplete ([1u8, 2u8, 3u8]) (read native byte order)
|
|
================
|
|
Input: [1u8, 2u8, 3u8, 4u8]
|
|
Result: Incomplete ([1u8, 2u8, 3u8, 4u8]) (read native byte order)
|
|
================
|
|
Input: [1u8, 2u8, 3u8, 4u8, 5u8]
|
|
Result: Incomplete ([1u8, 2u8, 3u8, 4u8, 5u8]) (read native byte order)
|
|
================
|
|
Input: [1u8, 2u8, 3u8, 4u8, 5u8, 6u8]
|
|
Result: Incomplete ([1u8, 2u8, 3u8, 4u8, 5u8, 6u8]) (read native byte order)
|
|
================
|
|
Input: [1u8, 2u8, 3u8, 4u8, 5u8, 7u8]
|
|
Result: Incomplete ([1u8, 2u8, 3u8, 4u8, 5u8, 7u8]) (read native byte order)
|
|
================
|
|
Input: [1u8, 2u8, 3u8, 4u8, 5u8, 7u8, 8u8]
|
|
Result: Incomplete ([1u8, 2u8, 3u8, 4u8, 5u8, 7u8, 8u8]) (read native byte order)
|
|
================
|
|
Input: [0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8] (LE: 72057594037927936) (BE: 1)
|
|
Result: 72057594037927936i64 (read native byte order)
|
|
================
|
|
Input: [255u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8] (LE: 255) (BE: -72057594037927936)
|
|
Result: 255i64 (read native byte order)
|
|
================
|
|
Input: [1u8, 1u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8] (LE: 257) (BE: 72339069014638592)
|
|
Result: 257i64 (read native byte order)
|