Skip to content

Commit 05571be

Browse files
committed
2 parents b2e2a52 + e3966a0 commit 05571be

File tree

6 files changed

+47
-15
lines changed

6 files changed

+47
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23

34
namespace SharpIpp.Protocol.Extensions
45
{
56
internal static class BinaryReaderExtensions
67
{
78
public static short ReadInt16BigEndian(this BinaryReader reader)
89
{
9-
return Bytes.Reverse(reader.ReadInt16());
10+
var value = reader.ReadInt16();
11+
12+
if (BitConverter.IsLittleEndian)
13+
value = Bytes.Reverse(value);
14+
15+
return value;
1016
}
1117

1218
public static int ReadInt32BigEndian(this BinaryReader reader)
1319
{
14-
return Bytes.Reverse(reader.ReadInt32());
15-
}
20+
var value = reader.ReadInt32();
1621

17-
public static short ReadInt16BigEndianAsync( this BinaryReader reader )
18-
{
19-
return Bytes.Reverse( reader.ReadInt16() );
20-
}
22+
if (BitConverter.IsLittleEndian)
23+
value = Bytes.Reverse(value);
2124

22-
public static int ReadInt32BigEndianAsync( this BinaryReader reader )
23-
{
24-
return Bytes.Reverse( reader.ReadInt32() );
25+
return value;
2526
}
2627
}
2728
}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23

34
namespace SharpIpp.Protocol.Extensions
45
{
56
internal static class BinaryWriterExtensions
67
{
78
public static void WriteBigEndian(this BinaryWriter writer, short value)
89
{
9-
writer.Write(Bytes.Reverse(value));
10+
if (BitConverter.IsLittleEndian)
11+
value = Bytes.Reverse(value);
12+
13+
writer.Write(value);
1014
}
1115

1216
public static void WriteBigEndian(this BinaryWriter writer, int value)
1317
{
14-
writer.Write(Bytes.Reverse(value));
18+
if (BitConverter.IsLittleEndian)
19+
value = Bytes.Reverse(value);
20+
21+
writer.Write(value);
1522
}
1623
}
1724
}

SharpIpp/Protocol/Models/MediaSize.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static MediaSize Create(Dictionary<string, IppAttribute[]> dict, IMapperA
3232
return new MediaSize
3333
{
3434
XDimension = mapper.MapFromDic<int?>(dict, nameof(XDimension).ConvertCamelCaseToDash()),
35-
YDimension = mapper.MapFromDic<int?>(dict, nameof(XDimension).ConvertCamelCaseToDash())
35+
YDimension = mapper.MapFromDic<int?>(dict, nameof(YDimension).ConvertCamelCaseToDash())
3636
};
3737
}
3838
}
Binary file not shown.
Binary file not shown.

SharpIppTests/SharpIppClientTests.cs

+24
Original file line numberDiff line numberDiff line change
@@ -938,5 +938,29 @@ public async Task Construct_ReadBinFileWithGetPrinterAttributes_ShouldBeMapped(s
938938
using SharpIppClient client = new(new HttpClient(), protocol);
939939
var mapped = client.Construct<GetPrinterAttributesResponse>(ippResponse);
940940
Assert.IsNotNull(mapped);
941+
}
942+
943+
[DataTestMethod]
944+
[DataRow("RawIppResponses/PrintJob_HP_Color_LaserJet_MFP_M476dn.bin")]
945+
public async Task Construct_ReadBinFileWithPrintJob_ShouldBeMapped(string path)
946+
{
947+
var protocol = new IppProtocol();
948+
await using var stream = new FileStream(path, FileMode.Open, FileAccess.Read);
949+
var ippResponse = await protocol.ReadIppResponseAsync(stream);
950+
using SharpIppClient client = new(new HttpClient(), protocol);
951+
var mapped = client.Construct<PrintJobResponse>(ippResponse);
952+
Assert.IsNotNull(mapped);
953+
}
954+
955+
[DataTestMethod]
956+
[DataRow("RawIppResponses/GetJobAttributes_HP_Color_LaserJet_MFP_M476dn.bin")]
957+
public async Task Construct_ReadBinFileWithGetJobAttributes_ShouldBeMapped(string path)
958+
{
959+
var protocol = new IppProtocol();
960+
await using var stream = new FileStream(path, FileMode.Open, FileAccess.Read);
961+
var ippResponse = await protocol.ReadIppResponseAsync(stream);
962+
using SharpIppClient client = new(new HttpClient(), protocol);
963+
var mapped = client.Construct<GetJobAttributesResponse>(ippResponse);
964+
Assert.IsNotNull(mapped);
941965
}
942966
}

0 commit comments

Comments
 (0)