Skip to content
This repository has been archived by the owner on May 27, 2022. It is now read-only.

Dart utf8 #125

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion serde-generate/runtime/dart/serde/binary_deserializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ abstract class BinaryDeserializer {
int deserializeVariantIndex();

String deserializeString() {
return String.fromCharCodes(deserializeUint8List());
return utf8.decode(deserializeUint8List());
}

int deserializeLength();
Expand Down
2 changes: 1 addition & 1 deletion serde-generate/runtime/dart/serde/binary_serializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions serde-generate/runtime/dart/serde/serde.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

library serde;

import 'dart:convert' show utf8;
import 'dart:typed_data';

import 'package:meta/meta.dart';
Expand Down
7 changes: 7 additions & 0 deletions serde-generate/runtime/dart/test/bincode_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 / ダミーテキスト');
});
}