Skip to content

Commit 91a28dc

Browse files
committed
Update README.md for version 2.1.0: enhance examples and correct dependency version
1 parent 5cd8121 commit 91a28dc

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

README.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Add this to your package's `pubspec.yaml` file:
2121

2222
``` yaml
2323
dependencies:
24-
pro_binary: ^2.0.0
24+
pro_binary: ^2.1.0
2525
```
2626
2727
Then, run `pub get` to install the package.
@@ -72,15 +72,22 @@ final writer = BinaryWriter(initialBufferSize: 64);
7272
7373
// Write operations
7474
writer.writeUint8(255);
75+
writer.writeInt8(-128);
76+
writer.writeUint16(65535, Endian.big);
77+
writer.writeInt16(-32768, Endian.big);
78+
writer.writeUint32(4294967295, Endian.big);
7579
writer.writeInt32(-1000, Endian.big);
76-
writer.writeFloat64(3.14);
80+
writer.writeUint64(9223372036854775807, Endian.big);
81+
writer.writeInt64(-9223372036854775808, Endian.big);
82+
writer.writeFloat32(3.14, Endian.big);
83+
writer.writeFloat64(3.14159, Endian.big);
7784
writer.writeBytes([1, 2, 3]);
7885
writer.writeString('text');
7986
8087
// Buffer operations
81-
final bytes = writer.toBytes(); // Get copy without reset
82-
final result = writer.takeBytes(); // Get and reset
83-
writer.clear(); // Reset without returning
88+
final bytes = writer.toBytes(); // Get view without reset
89+
final result = writer.takeBytes(); // Get view and reset
90+
writer.reset(); // Reset without returning
8491
print(writer.bytesWritten); // Check written size
8592
```
8693

@@ -91,14 +98,25 @@ final reader = BinaryReader(buffer);
9198
9299
// Read operations
93100
final u8 = reader.readUint8();
101+
final i8 = reader.readInt8();
102+
final u16 = reader.readUint16(Endian.big);
103+
final i16 = reader.readInt16(Endian.big);
104+
final u32 = reader.readUint32(Endian.big);
94105
final i32 = reader.readInt32(Endian.little);
95-
final f64 = reader.readFloat64();
106+
final u64 = reader.readUint64(Endian.big);
107+
final i64 = reader.readInt64(Endian.big);
108+
final f32 = reader.readFloat32(Endian.big);
109+
final f64 = reader.readFloat64(Endian.big);
96110
final bytes = reader.readBytes(10);
97111
final text = reader.readString(5);
98112
113+
// Peek without advancing position
114+
final peeked = reader.peekBytes(4); // View without consuming
115+
99116
// Navigation
100117
reader.skip(4); // Skip bytes
101118
final pos = reader.offset; // Current position
119+
final used = reader.usedBytes; // Bytes read so far
102120
reader.reset(); // Reset to start
103121
print(reader.availableBytes); // Remaining bytes
104122
```
@@ -111,7 +129,7 @@ All read operations validate boundaries and provide detailed error messages:
111129
try {
112130
reader.readUint32(); // Not enough bytes
113131
} catch (e) {
114-
// RangeError: Not enough bytes to read Uint32:
132+
// AssertionError: Not enough bytes to read Uint32:
115133
// required 4 bytes, available 2 bytes at offset 10
116134
}
117135
```

0 commit comments

Comments
 (0)