<commit_before>library nv.serialization;

import 'dart:convert';
import 'models.dart';

const _currentSerialVersion = 0;

const _TITLE = 'title', _LAST_MODIFIED = 'lastModified', _CONTENT = 'content',
  _VERSION = 'version';

// TODO: would love these to be const: https://codereview.chromium.org/22979003/
final _n2j = new _NoteToJsonConverter();
final _j2n = new _JsonToNoteConverter();

const NOTE_CODEC = const NoteCodec();

class NoteCodec extends Codec<Note, Object> {
  const NoteCodec();

  Converter<Note, Object> get encoder => _n2j;

  Converter<Object, Note> get decoder => _j2n;
}

class _NoteToJsonConverter extends Converter<Note, Object> {
  Object convert(Note note) => _toJson(note);
}

class _JsonToNoteConverter extends Converter<Object, Note> {
  Note convert(Object json) => _fromJson(json);
}

Note _fromJson(dynamic json) {
  Map<String, dynamic> map = json;

  assert(json[_VERSION] == _currentSerialVersion);

  var lastModified = DateTime.parse(json[_LAST_MODIFIED]);
  var content = json[_CONTENT];
<commit_msg>const converters are nice<commit_after>library nv.serialization;

import 'dart:convert';
import 'package:meta/meta.dart';
import 'models.dart';

const _currentSerialVersion = 0;

const _TITLE = 'title', _LAST_MODIFIED = 'lastModified', _CONTENT = 'content',
  _VERSION = 'version';

const NOTE_CODEC = const NoteCodec();

class NoteCodec extends Codec<Note, Object> {
  const NoteCodec();

  Converter<Note, Object> get encoder => const _NoteToJsonConverter();

  Converter<Object, Note> get decoder => const _JsonToNoteConverter();
}

class _NoteToJsonConverter extends Converter<Note, Object> {
  const _NoteToJsonConverter();

  @override
  Object convert(Note note) => _toJson(note);
}

class _JsonToNoteConverter extends Converter<Object, Note> {
  const _JsonToNoteConverter();

  @override
  Note convert(Object json) => _fromJson(json);
}

Note _fromJson(dynamic json) {
  Map<String, dynamic> map = json;

  assert(json[_VERSION] == _currentSerialVersion);

  var lastModified = DateTime.parse(json[_LAST_MODIFIED]);
  var content = json[_CONTENT];

{'fraction_non_alphanumeric': 0.11778731521220792, 'fraction_numerical': 0.006676204101096805, 'mean_word_length': 5.767741935483871, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5739129', 'n_tokens_mistral': 684, 'n_tokens_neox': 660, 'n_words': 173}