diff --git a/serde-generate/runtime/dart/serde/binary_deserializer.dart b/serde-generate/runtime/dart/serde/binary_deserializer.dart index cd4acaef4..2d2a0902a 100644 --- a/serde-generate/runtime/dart/serde/binary_deserializer.dart +++ b/serde-generate/runtime/dart/serde/binary_deserializer.dart @@ -111,7 +111,7 @@ abstract class BinaryDeserializer { int deserializeVariantIndex(); String deserializeString() { - return String.fromCharCodes(deserializeUint8List()); + return utf8.decode(deserializeUint8List()); } int deserializeLength(); diff --git a/serde-generate/runtime/dart/serde/binary_serializer.dart b/serde-generate/runtime/dart/serde/binary_serializer.dart index 7b15c170f..308e5c86f 100644 --- a/serde-generate/runtime/dart/serde/binary_serializer.dart +++ b/serde-generate/runtime/dart/serde/binary_serializer.dart @@ -123,7 +123,7 @@ abstract class BinarySerializer { void serializeVariantIndex(int index); void serializeString(String str) { - serializeUint8List(Uint8List.fromList(str.codeUnits)); + serializeUint8List(Uint8List.fromList(utf8.encode(str))); } void serializeLength(int len); diff --git a/serde-generate/runtime/dart/serde/serde.dart b/serde-generate/runtime/dart/serde/serde.dart index d96683fd3..583beb9b9 100644 --- a/serde-generate/runtime/dart/serde/serde.dart +++ b/serde-generate/runtime/dart/serde/serde.dart @@ -3,6 +3,7 @@ library serde; +import 'dart:convert' show utf8; import 'dart:typed_data'; import 'package:meta/meta.dart'; diff --git a/serde-generate/runtime/dart/test/bincode_test.dart b/serde-generate/runtime/dart/test/bincode_test.dart index 6e467cdd9..0ee29da2f 100644 --- a/serde-generate/runtime/dart/test/bincode_test.dart +++ b/serde-generate/runtime/dart/test/bincode_test.dart @@ -94,4 +94,11 @@ void main() { expect(() => serializer.serializeInt32(2147483648), throwsException); expect(() => serializer.serializeInt32(-2147483649), throwsException); }); + + test('serializeString', () { + final serializer = BincodeSerializer(); + serializer.serializeString('dummy text / ダミーテキスト'); + final deserializer = BincodeDeserializer(serializer.bytes); + expect(deserializer.deserializeString(), 'dummy text / ダミーテキスト'); + }); }