Slide 1

Slide 1 text

1SPUPϑΝΠϧΛ࢖༻͠ͳ͍ 1SPUP%BUBTUPSF࣮૷ 3VJ5BOBLB

Slide 2

Slide 2 text

3VJ5BOBLB OPUF "OESPJEΤϯδχΞ

Slide 3

Slide 3 text

w %BUB4UPSFͱ͸ w 1SFGFSFODFT%BUB4UPSFͱ1SPUP%BUB4UPSF w ࣮૷ํ๏ w Α͔ͬͨ఺

Slide 4

Slide 4 text

%BUB4UPSFͱ͸ "OESPJE+FUQBDLͷҰ෦Ͱ͋ΔσʔλετϨʔδιϦϡʔγϣϯͰ͢ɻ ,PUMJOίϧʔνϯͱ'MPXΛ࢖༻ͯ͠ɺσʔλΛඇಉظతʹɺҰ؏ੑͱτϥϯβΫγϣϯੑΛҡ࣋ ͠ͳ͕Βอଘ͠·͢ɻ 1SFGFSFODFT%BUB4UPSFͱ1SPUP%BUB4UPSFͷछྨ͕͋Γ·͢ɻ ࢀরIUUQTEFWFMPQFSBOESPJEDPNUPQJDMJCSBSJFTBSDIJUFDUVSFEBUBTUPSF IMKB

Slide 5

Slide 5 text

1SFGFSFODFT%BUB4UPSFͱ1SPUP%BUB4UPSF छྨ 1SFGFSFODFT%BUB4UPSF 1SPUP%BUB4UPSF εΩʔϚ ఆٛࡁΈεΩʔϚෆཁ ϓϩτίϧόοϑΝͰεΩʔϚఆ͕ٛඞཁ σʔλ΁ͷΞΫηε ΩʔΛ࢖ͬͯΞΫηε ΧελϜσʔλܕͷΠϯελϯεͱͯ͠ΞΫηε ܕ҆શੑ ͳ͠ ͋Γ ϝϦοτ ఆٛࡁΈͷεΩʔϚ͕ෆཁͳͨΊɺखܰʹར༻ ։࢝Ͱ͖Δ λΠϓηʔϑͰ͋ΔͨΊɺΑΓ҆શʹσʔλ؅ ཧ͕Մೳ σϝϦοτ λΠϓηʔϑͰ͸ͳ͍ͨΊɺ࣮ߦ࣌ΤϥʔͷϦε Ϋ͕͋Δ ϓϩτίϧόοϑΝͷ஌͕ࣝඞཁͱͳΔ దͨ͠࢖༻ํ๏ γϯϓϧͳΩʔόϦϡʔϖΞΛอଘ͍ͨ͠৔߹ ΧελϜσʔλܕΛ༻͍ͯɺΑΓෳࡶͳσʔλ Λอଘ͍ͨ͠৔߹

Slide 6

Slide 6 text

࣮૷खॱ w σʔλΫϥεΛ࡞੒ w ্هͷσʔλΫϥεͷ4FSJBMJ[FSΛ࡞੒

Slide 7

Slide 7 text

syntax = "proto3"; option java_package = "com.codelab.android.datastore"; option java_multiple_files = true; message UserPreferences { // filter for showing / hiding completed tasks bool show_completed = 1; }

Slide 8

Slide 8 text

syntax = "proto3"; option java_package = "com.codelab.android.datastore"; option java_multiple_files = true; message UserPreferences { // filter for showing / hiding completed tasks bool show_completed = 1; }

Slide 9

Slide 9 text

σʔλΫϥεͷ࡞੒ import com.squareup.moshi.Json import kotlinx.serialization.Serializable @Serializable data class Person( @Json(name = "name") var name: String = "", @Json(name = "age") var age: Int = 0, )

Slide 10

Slide 10 text

4FSJBMJ[FSΛ࡞੒ class PersonSerializer( private val stringFormat: StringFormat = Json { ignoreUnknownKeys = true encodeDefaults = true }, ) : Serializer { override val defaultValue: Person get() = Person() override suspend fun readFrom(input: InputStream): Person { try { val bytes = input.readBytes() val string = bytes.decodeToString() return stringFormat.decodeFromString(string) //ɹPersonΫϥεʹσίʔυͯ͠ಡΈऔΔ } catch (e: SerializationException) { throw CorruptionException("Cannot read stored data", e) } } override suspend fun writeTo(t: Person, output: OutputStream) { val string = stringFormat.encodeToString(t) val bytes = string.encodeToByteArray() // PersonΫϥε͔ΒΤϯίʔυͯ͠ॻ͖ࠐΉ withContext(Dispatchers.IO) { output.write(bytes) } } }

Slide 11

Slide 11 text

׬

Slide 12

Slide 12 text

ྑ͔ͬͨ͜ͱ w σʔλΫϥεͱQSPUPϑΝΠϧͷೋॏ؅ཧΛ͠ͳͯ͘Α͘ͳͬͨʂ w ϓϩτίϧόοϑΝͷ஌͕ࣝͳͯ͘΋Φοέʔʂ w ΧελϜΫϥεΛ%BUB4UPSFʹ֨ೲ͠΍͘͢ͳͬͨʂ w 4IBSF1SFGFSFODF΍LWTTDIFNF౳ϥΠϒϥϦ͔ΒͷҠߦ͕͠΍͘͢ͳͬ ͨʂ

Slide 13

Slide 13 text

5IBOLZPV