You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| Signed 64-bit value within JS-safe range |`int`| Works with default `int64` mapping and `@Int64Type` encodings. |
98
+
| Full signed 64-bit range |`Int64`| Preserves values outside the JS-safe range. |
99
+
| Unsigned 64-bit value |`Uint64`| Required for values that do not fit in signed or JS-safe Dart `int`. |
100
+
| 8/16/32-bit integer |`Int8`, `Int16`, `Int32`, `Uint8`, `Uint16`, `Uint32` or annotations | Use wrappers or numeric annotations to match peer runtimes exactly. |
101
+
102
+
`@Int64Type` controls the wire encoding of a Dart `int` field:
103
+
104
+
```dart
105
+
@ForyStruct()
106
+
class SafeCounter {
107
+
SafeCounter();
108
+
109
+
@Int64Type(encoding: LongEncoding.tagged)
110
+
int count = 0; // keep web values inside the JS-safe range
111
+
}
112
+
```
113
+
114
+
It does not make Dart `int` capable of storing every 64-bit value on web. For
115
+
full-range signed values, use `Int64`:
116
+
117
+
```dart
118
+
@ForyStruct()
119
+
class FullRangeCounter {
120
+
FullRangeCounter();
121
+
122
+
Int64 count = Int64(0);
123
+
}
124
+
```
125
+
126
+
For unsigned values, use `Uint64`:
127
+
128
+
```dart
129
+
@ForyStruct()
130
+
class StorageExtent {
131
+
StorageExtent();
132
+
133
+
Uint64 byteOffset = Uint64(0);
134
+
}
135
+
```
136
+
137
+
## Custom Serializers
138
+
139
+
Custom serializers can use the same `Buffer`, `WriteContext`, and `ReadContext`
140
+
APIs on VM and web. For 64-bit values:
141
+
142
+
- Use `buffer.writeInt64(Int64(...))` and `buffer.readInt64()` for full-range
143
+
signed 64-bit values.
144
+
- Use `buffer.writeUint64(Uint64(...))` and `buffer.readUint64()` for full-range
145
+
unsigned 64-bit values.
146
+
- Use `writeInt64FromInt`, `writeVarInt64FromInt`, and matching `AsInt` reads
147
+
only when the value is intended to be a Dart `int` and therefore must stay
148
+
JS-safe on web.
149
+
150
+
Example:
151
+
152
+
```dart
153
+
final class OffsetSerializer extends Serializer<StorageExtent> {
0 commit comments