Conversation
Owner
Author
|
エンコードの実装を見据えてHasDecodeを分離した |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
それと同時に、アーキテクチャとAPIの刷新を行った。
従来、
CodeGeneratorは複数のtypeを引数に取る関数を提供していた。その実装内部では、それら様々な関数の都合に応じて、動的なキャストをしていた。
これらはSwiftでの 型の種類 に応じて、生成時に様々な考慮が生じるためだが、
実装が各所に散らばってしまって見通しが悪かった。
そこで、型の種類に応じて処理が変化する部分を
TypeConverterprotocol に切り出して、CodeGeneratorは型に応じたTypeConverterを提供する役割にした。これまでの、型を引数に取る様々な関数は、
TypeConverterのメソッドに移し替えた。その結果、型の種類による分岐はその
TypeConverterを生成する箇所に集約して、個別の生成ロジックではそのような分岐を排除する事ができた。
この設計の元では、
TypeMapの機能は、特殊な専用のTypeConverterを提供するものと整理できる。それを
TypeMapConverterとして実装した。これによって、
TypeMapがどのように生成系の干渉しているのかが見やすくひとまとめにできた。その後、カスタムデコーダを指定する機能を簡単に実装する事ができた。
また、カスタムの
TypeConverterを注入するAPIを開放した。全く異なるJSON化戦略を導入することもできるようになった。