@@ -19,6 +19,12 @@ private def new_string_io(*bytes)
1919 io
2020end
2121
22+ private module ReadBytesConverter
23+ def self.from_io (io : IO , format = IO ::ByteFormat ::NetworkEndian ) : Int32
24+ io.read_bytes(Int32 , format: format)
25+ end
26+ end
27+
2228describe IO ::ByteFormat do
2329 describe " little endian" do
2430 describe " encode" do
@@ -130,6 +136,11 @@ describe IO::ByteFormat do
130136 float = io.read_bytes Float64 , IO ::ByteFormat ::LittleEndian
131137 float.should be_close(1.234 , 0.0001 )
132138 end
139+
140+ it " reads with converter" do
141+ io = new_string_io(0x78 , 0x56 , 0x34 , 0x12 )
142+ io.read_bytes(ReadBytesConverter , IO ::ByteFormat ::LittleEndian ).should eq 0x12345678 _i32
143+ end
133144 end
134145
135146 describe " from slice" do
@@ -248,6 +259,11 @@ describe IO::ByteFormat do
248259 float = io.read_bytes Float64 , IO ::ByteFormat ::BigEndian
249260 float.should be_close(1.234 , 0.0001 )
250261 end
262+
263+ it " reads with converter" do
264+ io = new_string_io(0x12 , 0x34 , 0x56 , 0x78 )
265+ io.read_bytes(ReadBytesConverter , IO ::ByteFormat ::BigEndian ).should eq 0x12345678 _i32
266+ end
251267 end
252268
253269 describe " from slice" do
0 commit comments