@@ -11,43 +11,45 @@ Any `get*` method (`getByte(index:)`, `getBytes(range:)`, `getBit(index:)`, …)
11
11
Here are the methods you can call:
12
12
13
13
``` swift
14
+ let binary = Binary (bytes : [0xDE , 0xAD , 0xBE , 0xEF , … ])
15
+
14
16
// Reads exactly 1 byte and
15
17
// increments the cursor by 1 byte
16
- try readByte ()
18
+ try binary. readByte ()
17
19
18
20
// Reads the next 4 bytes and
19
21
// increments the cursor by 4 bytes
20
- try readBytes (quantitiy : 4 )
22
+ try binary. readBytes (quantitiy : 4 )
21
23
22
24
// Reads the next 1 bit and
23
25
// increments the cursor by 1 bit
24
- try readBit ()
26
+ try binary. readBit ()
25
27
26
28
// Reads the next 4 bits and
27
29
// increments the cursor by 4 bits
28
- try readBits (quantitiy : 4 )
30
+ try binary. readBits (quantitiy : 4 )
29
31
```
30
32
31
33
## Example
32
34
33
- This shows how easy it is, to break down an ( IPv4 header) [ https://en.wikipedia.org/wiki/IPv4#Header ] .
35
+ This shows how easy it is, to break down an [ IPv4 header] ( https://en.wikipedia.org/wiki/IPv4#Header ) .
34
36
35
37
``` swift
36
38
let binary = Binary (bytes : [0b1_1_0_1_1_1_0_0 ])
37
- | | | | |
38
- | | | | try binary.bit () // 0
39
- | | | try binary.bit () // 0
40
- | | try binary.bit () // 1
41
- | try binary.bit () // 1
42
- try binary.bit () // 1
43
-
44
-
45
- ```
39
+ | | | | | | | |
40
+ | | | | | | | try binary.bit () // 0
41
+ | | | | | | try binary.bit () // 0
42
+ | | | | | try binary.bit () // 1
43
+ | | | | try binary.bit () // 1
44
+ | | | try binary.bit () // 1
45
+ | | try binary.bit () // 0
46
+ | try binary.bit () // 1
47
+ try binary.bit () // 1
48
+ ```
46
49
47
50
48
51
``` swift
49
52
let binary = Binary (bytes : [0x1B , 0x44 , … ])
50
-
51
53
let version = try binary.readBits (4 )
52
54
let internetHeaderLength = try binary.readBits (4 )
53
55
let differentiatedServicesCodePoint = try binary.readBits (6 )
@@ -57,14 +59,13 @@ let identification = try binary.readBytes(2)
57
59
let flags = try binary.readBits (4 )
58
60
let fragmentOffset = try binary.readBits (12 )
59
61
let timeToLive = try binary.readByte ()
60
- let protocol = try binary.readByte ()
62
+ let protocolNumber = try binary.readByte ()
61
63
let headerChecksum = try binary.readBytes (2 )
62
64
let sourceIpAddress = try binary.readBytes (4 )
63
65
let destinationIpAddress = try binary.readBytes (4 )
64
66
...
65
67
```
66
68
67
-
68
69
## License
69
70
70
71
BinaryKit is released under the [ MIT License] ( http://www.opensource.org/licenses/MIT ) .
0 commit comments