/* Ċ Ġ* ĠCopyright Ġ 2 0 1 7 ĠSquare ĠInc . Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ package Ġcom . squareup . sample . main workflow Ċ Ċ import Ġcom . squareup . sample . auth workflow . Auth Event Ċ import Ġcom . squareup . sample . auth workflow . Auth Launcher Ċ import Ġcom . squareup . sample . auth workflow . Auth State Ċ import Ġcom . squareup . sample . game workflow . Run Game Event Ċ import Ġcom . squareup . sample . game workflow . Run Game Launcher Ċ import Ġcom . squareup . sample . game workflow . Run Game Result Ċ import Ġcom . squareup . sample . game workflow . Run GameState Ċ import Ġcom . squareup . workflow . Snapshot Ċ import Ġcom . squareup . workflow . Workflow Pool Ċ import Ġcom . squareup . workflow . parse Ċ import Ġcom . squareup . workflow . read ByteString With Length Ċ import Ġcom . squareup . workflow . read Utf 8 With Length Ċ import Ġcom . squareup . workflow . write ByteString With Length Ċ import Ġcom . squareup . workflow . write Utf 8 With Length Ċ import Ġok io . ByteString Ċ import Ġkotlin . reflect . jvm . jvm Name Ċ Ċ /** Ċ Ġ* ĠThe Ġstate Ġof Ġ[ Main Reactor ]. ĠIndicates Ġwhich Ġnested Ġworkflow Ġis Ġrunning , Ġand Ġrecords Ċ Ġ* Ġthe Ġcurrent Ġnested Ġstate . Ċ Ġ*/ Ċ sealed Ġclass ĠMain State Ġ{ ĊĊĠ Ġinternal Ġdata Ġclass ĠAuth entic ating ( ĊĠĠĠ Ġval Ġauth Workflow : ĠWorkflow Pool . Handle < Auth State , ĠAuth Event , ĠString > Ġ= ĠAuth Launcher . handle () ĊĠ Ġ) Ġ: ĠMain State () ĊĊĠ Ġinternal Ġdata Ġclass ĠRunning Game ( ĊĠĠĠ Ġval Ġrun Game Workflow : ĠWorkflow Pool . Handle < Run GameState , ĠRun Game Event , ĠRun Game Result > Ġ= ĊĠĠĠĠĠ ĠRun Game Launcher . handle () ĊĠ Ġ) Ġ: ĠMain State () ĊĊĠ Ġfun Ġto Snapshot (): ĠSnapshot Ġ{ ĊĠĠĠ Ġreturn ĠSnapshot . write Ġ{ Ġsink Ġ-> ĊĠĠĠĠĠ Ġsink . write Utf 8 With Length ( this :: class . jvm Name ) ĊĊĠĠĠĠĠ Ġwhen Ġ( this ) Ġ{ ĊĠĠĠĠĠĠĠ Ġis ĠAuth entic ating Ġ-> Ġsink . write ByteString With Length ( auth Workflow . state . to Snapshot (). bytes ) ĊĠĠĠĠĠĠĠ Ġis ĠRunning Game Ġ-> Ġsink . write ByteString With Length ( run Game Workflow . state . to Snapshot (). bytes ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġfun Ġstarting State (): ĠMain State Ġ= ĊĠĠĠĠĠ ĠAuth entic ating () ĊĊĠĠĠ Ġfun Ġfrom Snapshot ( byte String : ĠByte String ): ĠMain State Ġ= Ġbyte String . parse Ġ{ ĊĠĠĠĠĠ Ġval Ġmain State Name Ġ= Ġit . read Utf 8 With Length () ĊĠĠĠĠĠ Ġval Ġdelegate ByteString Ġ= Ġit . read ByteString With Length () ĊĊĠĠĠĠĠ Ġreturn Ġwhen Ġ( main State Name ) Ġ{ ĊĠĠĠĠĠĠĠ ĠAuth entic ating :: class . jvm Name Ġ-> ĊĠĠĠĠĠĠĠĠĠ ĠAuth entic ating ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠAuth Launcher . handle ( Auth State . from Snapshot ( delegate ByteString )) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ ĠRunning Game :: class . jvm Name Ġ-> ĊĠĠĠĠĠĠĠĠĠ ĠRunning Game ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠRun Game Launcher . handle ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠRun GameState . from Snapshot ( delegate ByteString ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġelse Ġ-> Ġthrow ĠIllegalArgumentException (" Unrecognized Ġstate : Ġ$ main State Name ") ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ