Skip to content

Commit

Permalink
Merge pull request #68 from IO-Design-Team/feature/type-id-extension
Browse files Browse the repository at this point in the history
Type ID extension
  • Loading branch information
Rexios80 authored Feb 4, 2025
2 parents b5b8346 + dd30829 commit 6e8f715
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 165 deletions.
4 changes: 4 additions & 0 deletions hive/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.10.0

- Raises the maximum type ID from 223 to 65439

## 2.9.0

- Prints a warning when writing `int` or `List<int>` types in a WASM environment
Expand Down
1 change: 1 addition & 0 deletions hive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Hive CE is a spiritual continuation of Hive v2 with the following new features:
- Automatic type adapter generation using the `GenerateAdapters` annotation
- No more manually adding annotations to every type and field
- Generate adapters for classes outside the current package
- Extends the maximum type ID from `223` to `65439`

## Hive CE (v2) vs Hive v4 (Isar)

Expand Down
16 changes: 15 additions & 1 deletion hive/lib/src/binary/binary_reader_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:hive_ce/src/crypto/crc32.dart';
import 'package:hive_ce/src/object/hive_list_impl.dart';
import 'package:hive_ce/src/registry/type_registry_impl.dart';
import 'package:hive_ce/src/util/extensions.dart';
import 'package:meta/meta.dart';

/// Not part of public API
class BinaryReaderImpl extends BinaryReader {
Expand Down Expand Up @@ -242,6 +243,19 @@ class BinaryReaderImpl extends BinaryReader {
return HiveListImpl.lazy(boxName, keys);
}

/// Read a type ID and handle extension
@pragma('vm:prefer-inline')
@pragma('dart2js:tryInline')
@visibleForTesting
int readTypeId() {
final typeId = readByte();
if (typeId == FrameValueType.typeIdExtension) {
return readWord();
} else {
return typeId;
}
}

/// Not part of public API
Frame? readFrame({
HiveCipher? cipher,
Expand Down Expand Up @@ -296,7 +310,7 @@ class BinaryReaderImpl extends BinaryReader {

@override
dynamic read([int? typeId]) {
typeId ??= readByte();
typeId ??= readTypeId();
switch (typeId) {
case FrameValueType.nullT:
return null;
Expand Down
2 changes: 1 addition & 1 deletion hive/lib/src/binary/binary_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ abstract class BinaryWriter {
void writeHiveList(HiveList list, {bool writeLength = true});

/// Write any [value].
void write<T>(T value, {bool writeTypeId = true});
void write<T>(T value, {bool withTypeId = true});
}
Loading

0 comments on commit 6e8f715

Please sign in to comment.