Skip to content

Commit 2143bd0

Browse files
committed
Update README.md
1 parent 574479e commit 2143bd0

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

README.md

+18-17
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,45 @@ Any `get*` method (`getByte(index:)`, `getBytes(range:)`, `getBit(index:)`, …)
1111
Here are the methods you can call:
1212

1313
```swift
14+
let binary = Binary(bytes: [0xDE, 0xAD, 0xBE, 0xEF, ])
15+
1416
// Reads exactly 1 byte and
1517
// increments the cursor by 1 byte
16-
try readByte()
18+
try binary.readByte()
1719

1820
// Reads the next 4 bytes and
1921
// increments the cursor by 4 bytes
20-
try readBytes(quantitiy: 4)
22+
try binary.readBytes(quantitiy: 4)
2123

2224
// Reads the next 1 bit and
2325
// increments the cursor by 1 bit
24-
try readBit()
26+
try binary.readBit()
2527

2628
// Reads the next 4 bits and
2729
// increments the cursor by 4 bits
28-
try readBits(quantitiy: 4)
30+
try binary.readBits(quantitiy: 4)
2931
```
3032

3133
## Example
3234

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).
3436

3537
```swift
3638
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+
```
4649

4750

4851
```swift
4952
let binary = Binary(bytes: [0x1B, 0x44, ])
50-
5153
let version = try binary.readBits(4)
5254
let internetHeaderLength = try binary.readBits(4)
5355
let differentiatedServicesCodePoint = try binary.readBits(6)
@@ -57,14 +59,13 @@ let identification = try binary.readBytes(2)
5759
let flags = try binary.readBits(4)
5860
let fragmentOffset = try binary.readBits(12)
5961
let timeToLive = try binary.readByte()
60-
let protocol = try binary.readByte()
62+
let protocolNumber = try binary.readByte()
6163
let headerChecksum = try binary.readBytes(2)
6264
let sourceIpAddress = try binary.readBytes(4)
6365
let destinationIpAddress = try binary.readBytes(4)
6466
...
6567
```
6668

67-
6869
## License
6970

7071
BinaryKit is released under the [MIT License](http://www.opensource.org/licenses/MIT).

0 commit comments

Comments
 (0)