Skip to content

Commit

Permalink
String fix
Browse files Browse the repository at this point in the history
  • Loading branch information
simc committed Jan 20, 2025
1 parent 5b1ef8d commit 0b959ca
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 105 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Bump dependencies, to support latest analyzer
- Fixed support for freezed classes and from factories
- Fixed bug with serialization of large Strings

# 0.3.1

Expand Down
100 changes: 0 additions & 100 deletions crimson_test/lib/bench.dart

This file was deleted.

4 changes: 2 additions & 2 deletions crimson_test/test/from_crimson_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class FCFreezed with _$FCFreezed {

factory FCFreezed.fromCrimson(Crimson c) {
final map = c.read() as Map<String, dynamic>;
return FCFreezed(name: map['name'], age: map['age']);
return FCFreezed(name: map['name'] as String, age: map['age'] as int);
}
}

Expand All @@ -59,7 +59,7 @@ class FCModel {

factory FCModel.fromCrimson(Crimson c) {
final map = c.read() as Map<String, dynamic>;
return FCModel(map['name'], map['age']);
return FCModel(map['name'] as String, map['age'] as int);
}

void toCrimson(CrimsonWriter w) {
Expand Down
5 changes: 3 additions & 2 deletions lib/src/crimson_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import 'dart:math';
import 'dart:typed_data';

import 'package:crimson/src/consts.dart';

/// A writer that writes JSON to a [Uint8List].
Expand All @@ -17,6 +16,7 @@ class CrimsonWriter {
final bufferView = Uint8List.view(_buffer.buffer, 0, _offset);
_buffers.add(bufferView);
_buffer = Uint8List(max(size, _buffer.length) * 2);
_offset = 0;
}
}

Expand Down Expand Up @@ -44,8 +44,9 @@ class CrimsonWriter {
}

if (i < value.length) {
_offset = offset;
_ensure((value.length - i) * 3 + 1);

offset = _offset;
for (; i < value.length; i++) {
final char = value.codeUnitAt(i);
if (char < oneByteLimit) {
Expand Down
4 changes: 3 additions & 1 deletion lib/src/generator/class_decode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ String _read(DartType type, bool nullable) {
return 'readNum$orNull()';
} else if (type.isDartCoreString) {
return 'readString$orNull()';
} else if (type is DynamicType || type.isDartCoreBool) {
} else if (type.isDartCoreBool) {
return 'read() == true';
} else if (type is DynamicType) {
return 'read()';
} else if (type.element?.name == 'DateTime') {
return '$skipNull DateTime.parse(readString())';
Expand Down

0 comments on commit 0b959ca

Please sign in to comment.