Skip to content

Commit 64e398a

Browse files
committed
Set SyncCommand to their real value
1 parent 5108b52 commit 64e398a

3 files changed

Lines changed: 37 additions & 63 deletions

File tree

AdvancedSharpAdbClient.Tests/Extensions/SyncCommandConverterTests.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ public void GetCommandNullTest() =>
1616
public void GetCommandInvalidNumberOfBytesTest() =>
1717
_ = Assert.Throws<ArgumentOutOfRangeException>(() => SyncCommandConverter.GetCommand([]));
1818

19-
[Fact]
20-
public void GetCommandInvalidCommandTest() =>
21-
_ = Assert.Throws<ArgumentOutOfRangeException>(() => SyncCommandConverter.GetCommand("QMTV"u8));
22-
23-
[Fact]
24-
public void GetBytesInvalidCommandTest() =>
25-
_ = Assert.Throws<ArgumentOutOfRangeException>(() => ((SyncCommand)99).GetBytes());
26-
2719
[Fact]
2820
public void SyncCommandConverterTest()
2921
{

AdvancedSharpAdbClient/Extensions/SyncCommandConverter.cs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,7 @@ public static class SyncCommandConverter
2222
/// Gets the byte array that represents the <see cref="SyncCommand"/>.
2323
/// </summary>
2424
/// <returns>A byte array that represents the <see cref="SyncCommand"/>.</returns>
25-
public byte[] GetBytes()
26-
{
27-
if (command == 0)
28-
{
29-
return [0, 0, 0, 0];
30-
}
31-
32-
if (command is < SyncCommand.STAT or > SyncCommand.DNT2)
33-
{
34-
throw new ArgumentOutOfRangeException(nameof(command), $"{command} is not a valid sync command");
35-
}
36-
37-
string commandText = command.ToString();
38-
byte[] commandBytes = AdbClient.Encoding.GetBytes(commandText);
39-
40-
return commandBytes;
41-
}
25+
public byte[] GetBytes() => BitConverter.GetBytes((int)command);
4226

4327
/// <summary>
4428
/// Returns an enumerator that iterates through the <see cref="GetBytes(SyncCommand)"/>.
@@ -60,8 +44,7 @@ public static SyncCommand GetCommand(byte[] value)
6044
throw new ArgumentOutOfRangeException(nameof(value));
6145
}
6246

63-
string commandText = AdbClient.Encoding.GetString(value);
64-
return commandText == "\0\0\0\0" ? 0 : Enum.TryParse(commandText, true, out SyncCommand result) ? result : throw new ArgumentOutOfRangeException(nameof(value), $"{commandText} is not a valid sync command");
47+
return (SyncCommand)BitConverter.ToInt32(value);
6548
}
6649

6750
#if HAS_BUFFERS
@@ -77,8 +60,7 @@ public static SyncCommand GetCommand(ReadOnlySpan<byte> value)
7760
throw new ArgumentOutOfRangeException(nameof(value));
7861
}
7962

80-
string commandText = AdbClient.Encoding.GetString(value);
81-
return commandText == "\0\0\0\0" ? 0 : Enum.TryParse(commandText, true, out SyncCommand result) ? result : throw new ArgumentOutOfRangeException(nameof(value), $"{commandText} is not a valid sync command");
63+
return (SyncCommand)BitConverter.ToInt32(value);
8264
}
8365
#endif
8466
}

AdvancedSharpAdbClient/Models/Enums/SyncCommand.cs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,84 +12,84 @@ public enum SyncCommand
1212
/// <summary>
1313
/// Stat a file.
1414
/// </summary>
15-
STAT = 1,
15+
STAT = 'S' | ('T' << 8) | ('A' << 16) | ('T' << 24),
1616

1717
/// <summary>
18-
/// List the files in a folder.
18+
/// Stat a file v2.
1919
/// </summary>
20-
LIST,
20+
/// <remarks>Need Android 8 or above.</remarks>
21+
STA2 = 'S' | ('T' << 8) | ('A' << 16) | ('2' << 24),
2122

2223
/// <summary>
23-
/// Send a file to device.
24+
/// Stat a list v2.
2425
/// </summary>
25-
SEND,
26+
/// <remarks>Need Android 8 or above.</remarks>
27+
LST2 = 'L' | ('S' << 8) | ('T' << 16) | ('2' << 24),
2628

2729
/// <summary>
28-
/// Retrieve a file from device.
30+
/// List the files in a folder.
2931
/// </summary>
30-
RECV,
32+
LIST = 'L' | ('I' << 8) | ('S' << 16) | ('T' << 24),
3133

3234
/// <summary>
33-
/// A directory entry.
35+
/// List the files in a folder v2.
3436
/// </summary>
35-
DENT,
37+
/// <remarks>Need Android 11 or above.</remarks>
38+
LIS2 = 'L' | ('I' << 8) | ('S' << 16) | ('2' << 24),
3639

3740
/// <summary>
38-
/// The operation has completed.
41+
/// A directory entry.
3942
/// </summary>
40-
DONE,
43+
DENT = 'D' | ('E' << 8) | ('N' << 16) | ('T' << 24),
4144

4245
/// <summary>
43-
/// Marks the start of a data packet.
46+
/// A directory entry v2.
4447
/// </summary>
45-
DATA,
48+
DNT2 = 'D' | ('N' << 8) | ('T' << 16) | ('2' << 24),
4649

4750
/// <summary>
48-
/// The server has acknowledged the request.
51+
/// Send a file to device.
4952
/// </summary>
50-
OKAY,
53+
SEND = 'S' | ('E' << 8) | ('N' << 16) | ('D' << 24),
5154

5255
/// <summary>
53-
/// The operation has failed.
56+
/// Retrieve a file from device v2.
5457
/// </summary>
55-
FAIL,
58+
SND2 = 'S' | ('N' << 8) | ('D' << 16) | ('2' << 24),
5659

5760
/// <summary>
58-
/// The server has acknowledged the request.
61+
/// Retrieve a file from device.
5962
/// </summary>
60-
QUIT,
63+
RECV = 'R' | ('E' << 8) | ('C' << 16) | ('V' << 24),
6164

6265
/// <summary>
63-
/// Stat a file v2.
66+
/// Retrieve a file from device v2.
6467
/// </summary>
65-
/// <remarks>Need Android 8 or above.</remarks>
66-
STA2,
68+
RCV2 = 'R' | ('C' << 8) | ('V' << 16) | ('2' << 24),
6769

6870
/// <summary>
69-
/// Stat a list v2.
71+
/// The operation has completed.
7072
/// </summary>
71-
/// <remarks>Need Android 8 or above.</remarks>
72-
LST2,
73+
DONE = 'D' | ('O' << 8) | ('N' << 16) | ('E' << 24),
7374

7475
/// <summary>
75-
/// List the files in a folder v2.
76+
/// Marks the start of a data packet.
7677
/// </summary>
77-
/// <remarks>Need Android 11 or above.</remarks>
78-
LIS2,
78+
DATA = 'D' | ('A' << 8) | ('T' << 16) | ('A' << 24),
7979

8080
/// <summary>
81-
/// Retrieve a file from device v2.
81+
/// The server has acknowledged the request.
8282
/// </summary>
83-
SND2,
83+
OKAY = 'O' | ('K' << 8) | ('A' << 16) | ('Y' << 24),
8484

8585
/// <summary>
86-
/// Retrieve a file from device v2.
86+
/// The operation has failed.
8787
/// </summary>
88-
RCV2,
88+
FAIL = 'F' | ('A' << 8) | ('I' << 16) | ('L' << 24),
8989

9090
/// <summary>
91-
/// A directory entry v2.
91+
/// The server has acknowledged the request.
9292
/// </summary>
93-
DNT2
93+
QUIT = 'Q' | ('U' << 8) | ('I' << 16) | ('T' << 24)
9494
}
9595
}

0 commit comments

Comments
 (0)