package Ġcom . clo u way . kc q rs . client Ċ Ċ import Ġcom . clo u way . kc q rs . core . Aggregate Ċ import Ġcom . clo u way . kc q rs . core . Binary Ċ import Ġcom . clo u way . kc q rs . core . Event Payload Ċ import Ġcom . clo u way . kc q rs . core . Event Store Ċ import Ġcom . clo u way . kc q rs . core . GetAll Events Request Ċ import Ġcom . clo u way . kc q rs . core . GetAll Events Response Ċ import Ġcom . clo u way . kc q rs . core . Get Events From Streams Request Ċ import Ġcom . clo u way . kc q rs . core . Get Events Response Ċ import Ġcom . clo u way . kc q rs . core . Indexed Event Ċ import Ġcom . clo u way . kc q rs . core . Position Ċ import Ġcom . clo u way . kc q rs . core . Re vert Events Response Ċ import Ġcom . clo u way . kc q rs . core . Save Events Request Ċ import Ġcom . clo u way . kc q rs . core . Save Events Response Ċ import Ġcom . clo u way . kc q rs . core . Save Options Ċ import Ġcom . clo u way . kc q rs . core . Snapshot Ċ import Ġcom . clo u way . kc q rs . core . Stream Key Ċ import Ġcom . google . api . client . http . Generic Url Ċ import Ġcom . google . api . client . http . HttpRequest Factory Ċ import Ġcom . google . api . client . http . HttpStatusCode s Ċ import Ġcom . google . api . client . http . json . Json Http Content Ċ import Ġcom . google . api . client . json . Generic Json Ċ import Ġcom . google . api . client . json . gson . Gson Factory Ċ import Ġcom . google . api . client . util . Key Ċ import Ġjava . io . IOException Ċ import Ġjava . net . URL Ċ import Ġjava . net . URL Encoder Ċ import Ġjava . util . Arrays Ċ Ċ /** Ċ Ġ* ĠHttp Event Store Ġis Ġan Ġimplementation Ġof ĠEvent Store Ġwhich Ġuses ĠREST Ġapi Ġfor Ġstoring Ġand Ġretrieving Ġof Ġevents . Ċ Ġ* Ċ Ġ* Ġ@ author ĠM iro sl av ĠGen ov Ġ( mi ro sl av . gen ov @ clo u way . com ) Ċ Ġ*/ Ċ class ĠHttp Event Store ( Ċ ĉ private Ġval Ġendpoint : ĠURL , Ċ ĉ private Ġval Ġrequest Factory : ĠHttpRequest Factory , Ċ ĉ private Ġval Ġtimeout : ĠInt Ġ= Ġ 6 0 0 0 0 Ċ ) Ġ: ĠEvent Store Ġ{ ĊĉĊ ĉ override Ġfun Ġsave Events ( request : ĠSave Events Request , Ġsave Options : ĠSave Options ): ĠSave Events Response Ġ{ Ċĉ ĉ val Ġkey Ġ= ĠStream Key . from ( request . stream ) Ċĉ ĉ val Ġaggregate Id Ġ= Ġkey . aggregate Id Ċĉ ĉ val Ġaggregate Type Ġ= Ġrequest . aggregate Type ĊĉĉĊĉ ĉ val Ġrequest Events Ġ= Ċĉĉ ĉ request . events . map Ġ{ Ċĉĉĉ ĉ Event Payload Dto ( it . kind , Ġit . timestamp , Ġit . identity Id , Ġit . data . payload . toString ( Charsets . UTF _ 8 )) Ċĉĉ ĉ } ĊĉĉĊĉ ĉ try Ġ{ Ċĉĉ ĉ var Ġsnapshot Dto : ĠSnapshot Dto ? Ġ= Ġnull Ċĉĉ ĉ if Ġ( save Options . create Snapshot . required Ġ&& Ġsave Options . create Snapshot . snapshot Ġ!= Ġnull ) Ġ{ Ċĉĉĉ ĉ snapshot Dto Ġ= ĠSnapshot Dto ( Ċĉĉĉĉ ĉ save Options . create Snapshot . snapshot !!. version , Ċĉĉĉĉ ĉ Binary Dto ( save Options . create Snapshot . snapshot !!. data . payload ) Ċĉĉĉ ĉ ) Ċĉĉ ĉ } Ċĉĉ ĉ val Ġreq Ġ= Ġrequest Factory . build Post Request ( Ċĉĉĉ ĉ Generic Url ("$ endpoint / v 1 / aggreg ates "), Ċĉĉĉ ĉ Json Http Content ( Ċĉĉĉĉ ĉ Gson Factory . getDefaultInstance (), Ċĉĉĉĉ ĉ Save Events Request Dto ( Ċĉĉĉĉĉ ĉ aggregate Id , Ċĉĉĉĉĉ ĉ aggregate Type , Ċĉĉĉĉĉ ĉ save Options . version , Ċĉĉĉĉĉ ĉ save Options . topic Name , Ċĉĉĉĉĉ ĉ request Events , Ċĉĉĉĉĉ ĉ save Options . create Snapshot . required , Ċĉĉĉĉĉ ĉ snapshot Dto Ċĉĉĉĉ ĉ ) Ċĉĉĉ ĉ ) Ċĉĉ ĉ ). set Connect Timeout ( timeout ). set Read Timeout ( timeout ) ĊĉĉĉĊĉĉ ĉ req . throw Exception On Execute Error Ġ= Ġfalse ĊĉĉĉĊĉĉ ĉ val Ġresponse Ġ= Ġreq . execute () ĊĉĉĉĊĉĉ ĉ if Ġ( response . is Success StatusCode ) Ġ{ Ċĉĉĉ ĉ val Ġresp Ġ= Ġresponse . parse As ( Save Events Response Dto :: class . java ) Ċĉĉĉ ĉ return ĠSave Events Response . Success ( resp . version , Ġresp . sequence Ids , ĠAggregate ( aggregate Type , Ġnull , Ġresp . version , Ġresp . aggregate . events . map Ġ{ ĠEvent Payload ( aggregate Id , Ġit . kind , Ġit . timestamp , Ġit . identity Id , ĠBinary ( it . payload )) Ġ})) Ċĉĉ ĉ } ĊĉĉĉĊĉĉ ĉ if Ġ( response . statusCode Ġ== ĠHttpStatusCode s . STATUS _ CODE _ CONF LI CT ) Ġ{ Ċĉĉĉ ĉ val Ġresp Ġ= Ġresponse . parse As ( Save Events Response Dto :: class . java ) Ċĉĉĉ ĉ return ĠSave Events Response . Event Collision ( resp . version ) Ċĉĉ ĉ } ĊĉĉĉĊĉĉ ĉ if Ġ( response . statusCode Ġ== ĠHttpStatusCode s . STATUS _ CODE _ UN PROCESS ABLE _ ENTITY ) Ġ{ Ċĉĉĉ ĉ val Ġresp Ġ= Ġresponse . parse As ( Snapshot Required Dto :: class . java ) Ċĉĉĉ ĉ var Ġsnapshot : ĠSnapshot ? Ġ= Ġnull Ċĉĉĉ ĉ if Ġ( resp . current Snapshot Ġ!= Ġnull ) Ġ{ Ċĉĉĉĉ ĉ snapshot Ġ= ĠSnapshot ( resp . current Snapshot !!. version , ĠBinary ( resp . current Snapshot !!. data !!. payload )) Ċĉĉĉ ĉ } Ċĉĉĉ ĉ return ĠSave Events Response . Snapshot Required ( resp . current Events . map Ġ{ Ċĉĉĉĉ ĉ Event Payload ( Ċĉĉĉĉĉ ĉ aggregate Id , Ċĉĉĉĉĉ ĉ it . kind , Ċĉĉĉĉĉ ĉ it . timestamp , Ċĉĉĉĉĉ ĉ it . identity Id , Ċĉĉĉĉĉ ĉ Binary ( it . payload ), Ċĉĉĉĉ ĉ ) Ċĉĉĉ ĉ }, Ġsnapshot , Ġresp . version ) Ċĉĉ ĉ } ĊĉĉĉĊĉĉ ĉ if Ġ( response . statusCode Ġ== ĠHttpStatusCode s . STATUS _ CODE _ BAD _ GATE WAY ) Ġ{ Ċĉĉĉ ĉ return ĠSave Events Response . Error (" Unable Ġto Ġpublish Ġevent ") Ċĉĉ ĉ } ĊĉĉĉĊĉ ĉ } Ġcatch Ġ( ex : ĠIOException ) Ġ{ Ċĉĉ ĉ return ĠSave Events Response . Error In Communication ( ex . message !! ) Ċĉ ĉ } Ċĉ ĉ return ĠSave Events Response . Error (" Generic ĠError ") Ċ ĉ } ĊĉĊ ĉ override Ġfun Ġget Events From Streams ( request : ĠGet Events From Streams Request ): ĠGet Events Response Ġ{ Ċĉ ĉ val Ġstreams Ġ= Ġrequest . streams Ċĉ ĉ val Ġstream Ġ= Ġstreams . first () Ċĉ ĉ val Ġkey Ġ= ĠStream Key . from ( stream ) ĊĉĉĊĉ ĉ val ĠhttpRequest Ġ= Ċĉĉ ĉ request Factory . build GetRequest ( Generic Url ("$ endpoint / v 2 / aggreg ates /${ key . aggregate Id }? aggregate Type =${ key . aggregate Type } ")) Ċĉĉĉ ĉ . set Connect Timeout ( timeout ). set Read Timeout ( timeout ) Ċĉ ĉ httpRequest . headers . set (" Accept - version ", Ġ" v 2 ") Ċĉ ĉ httpRequest . throw Exception On Execute Error Ġ= Ġfalse Ċĉ ĉ try Ġ{ Ċĉĉ ĉ val Ġresponse Ġ= ĠhttpRequest . execute () ĊĉĉĉĊĉĉ ĉ // ĠAggregate Ġwas Ġnot Ġfound Ġand Ġno Ġevents Ġcannot Ġbe Ġreturned Ċĉĉ ĉ if Ġ( response . statusCode Ġ== ĠHttpStatusCode s . STATUS _ CODE _ NOT _ FOUND ) Ġ{ Ċĉĉĉ ĉ return ĠGet Events Response . Aggregate NotFound ( aggregate Ids Ġ= ĠlistOf ( key . aggregate Id ), Ġaggregate Type Ġ= Ġkey . aggregate Type ) Ċĉĉ ĉ } ĊĉĉĉĊĉĉ ĉ if Ġ( response . is Success StatusCode ) Ġ{ Ċĉĉĉ ĉ val Ġresp Ġ= Ġresponse . parse As ( Get Events Response Dto :: class . java ) ĊĉĉĉĉĊĉĉĉ ĉ val Ġaggreg ates Ġ= Ġresp . aggreg ates . map Ġ{ Ċĉĉĉĉ ĉ adapt ( key . aggregate Id , Ġit ) Ċĉĉĉ ĉ } ĊĉĉĉĉĊĉĉĉ ĉ return ĠGet Events Response . Success ( aggreg ates ) Ċĉĉ ĉ } ĊĉĉĉĊĉĉ ĉ return ĠGet Events Response . Error (" got Ġunknown Ġerror ") ĊĉĉĉĊĉ ĉ } Ġcatch Ġ( ex : ĠIOException ) Ġ{ Ċĉĉ ĉ return ĠGet Events Response . Error In Communication ( ex . message !! ) Ċĉ ĉ } Ċ ĉ } ĊĉĊĉĊ ĉ override Ġfun ĠgetAll Events ( request : ĠGetAll Events Request ): ĠGetAll Events Response Ġ{ Ċĉ ĉ val Ġall Ġ= ĠURL Encoder . encode ("\ $ all ", Ġ" UTF - 8 ") ĊĉĉĊĉ ĉ val Ġstreams Ġ= Ġrequest . streams . join ToString ( separator Ġ= Ġ", ") ĊĉĉĊĉ ĉ val Ġstreams Param Ġ= Ġif Ġ( streams . isNotEmpty ()) Ġ"& streams =$ streams " Ġelse Ġ"" ĊĉĉĊĉ ĉ val Ġurl Ġ= Ġendpoint . toString () Ġ+ Ġ"/ v 2 / aggreg ates /$ all ? from Position =${ Ċĉĉ ĉ request . position ?. value Ċĉĉĉ ĉ ?: Ġ 0 Ċĉ ĉ }& max Count =${ request . max Count }& read Direction =${ request . read Direction . name }$ streams Param " Ċĉ ĉ val Ġreq Ġ= Ġrequest Factory . build GetRequest ( Generic Url ( url )) Ċĉĉ ĉ . set Connect Timeout ( timeout ). set Read Timeout ( timeout ) Ċĉ ĉ req . headers . set (" Accept - version ", Ġ" v 2 ") Ċĉ ĉ req . throw Exception On Execute Error Ġ= Ġfalse Ċĉ ĉ try Ġ{ Ċĉĉ ĉ val Ġresponse Ġ= Ġreq . execute () ĊĉĉĉĊĉĉ ĉ // ĠAggregate Ġwas Ġnot Ġfound Ġand Ġno Ġevents Ġcannot Ġbe Ġreturned Ċĉĉ ĉ if Ġ( response . statusCode Ġ== ĠHttpStatusCode s . STATUS _ CODE _ NOT _ FOUND ) Ġ{ Ċĉĉĉ ĉ return ĠGetAll Events Response . Success ( listOf (), Ġrequest . read Direction , Ġnull ) Ċĉĉ ĉ } ĊĉĉĉĊĉĉ ĉ if Ġ( response . is Success StatusCode ) Ġ{ Ċĉĉĉ ĉ val Ġresp Ġ= Ġresponse . parse As ( GetAll Events Response Dto :: class . java ) Ċĉĉĉ ĉ val Ġevents Ġ= Ġresp . events . map Ġ{ Ċĉĉĉĉ ĉ Indexed Event ( Ċĉĉĉĉĉ ĉ Position ( it . position ), Ċĉĉĉĉĉ ĉ it . tenant , Ċĉĉĉĉĉ ĉ it . aggregate Type , Ċĉĉĉĉĉ ĉ it . version , Ċĉĉĉĉĉ ĉ Event Payload ( Ċĉĉĉĉĉĉ ĉ "", Ċĉĉĉĉĉĉ ĉ it . payload . kind , Ċĉĉĉĉĉĉ ĉ it . payload . timestamp , Ċĉĉĉĉĉĉ ĉ it . payload . identity Id , Ċĉĉĉĉĉĉ ĉ Binary ( it . payload . payload ) Ċĉĉĉĉĉ ĉ ) Ċĉĉĉĉ ĉ ) Ċĉĉĉ ĉ } ĊĉĉĉĉĊĉĉĉ ĉ return ĠGetAll Events Response . Success ( events , Ġrequest . read Direction , ĠPosition ( resp . next Position Ġ?: Ġ 0 )) Ċĉĉ ĉ } ĊĉĉĉĊĉĉ ĉ return ĠGetAll Events Response . Error (" got Ġunknown Ġerror ") ĊĉĉĉĊĉ ĉ } Ġcatch Ġ( ex : ĠIOException ) Ġ{ Ċĉĉ ĉ return ĠGetAll Events Response . Error In Communication ( ex . message !! ) Ċĉ ĉ } Ċ ĉ } ĊĉĊ ĉ override Ġfun Ġrevert Last Events ( tenant : ĠString , Ġstream : ĠString , Ġcount : ĠInt ): ĠRe vert Events Response Ġ{ Ċĉ ĉ val Ġrequest Ġ= Ġrequest Factory . build Patch Request ( Ċĉĉ ĉ Generic Url ("$ endpoint / v 1 / aggreg ates /$ stream ?& aggregate Type =$ tenant "), Ċĉĉ ĉ Json Http Content ( Gson Factory . getDefaultInstance (), ĠRe vert Events Request Dto ( stream , Ġcount )) Ċĉ ĉ ). set Connect Timeout ( timeout ). set Read Timeout ( timeout ) Ċĉ ĉ request . headers . set (" Accept - version ", Ġ" v 2 ") Ċĉ ĉ request . throw Exception On Execute Error Ġ= Ġfalse Ċĉ ĉ try Ġ{ Ċĉĉ ĉ val Ġresponse Ġ= Ġrequest . execute () ĊĉĉĉĊĉĉ ĉ // ĠAggregate Ġwas Ġnot Ġfound , Ġso Ġno Ġevents Ġcannot Ġbe Ġreturned Ċĉĉ ĉ if Ġ( response . statusCode Ġ== ĠHttpStatusCode s . STATUS _ CODE _ NOT _ FOUND ) Ġ{ Ċĉĉĉ ĉ return ĠRe vert Events Response . Aggregate NotFound ( stream , Ġtenant ) Ċĉĉ ĉ } ĊĉĉĉĊĉĉ ĉ if Ġ( response . is Success StatusCode ) Ġ{ Ċĉĉĉ ĉ return ĠRe vert Events Response . Success ( listOf ()) Ċĉĉ ĉ } ĊĉĉĉĊĉĉ ĉ return ĠRe vert Events Response . Error (" Generic ĠError ") ĊĉĉĉĊĉ ĉ } Ġcatch Ġ( ex : ĠIOException ) Ġ{ Ċĉĉ ĉ return ĠRe vert Events Response . Error (" Communication ĠError ") Ċĉ ĉ } Ċ ĉ } Ċĉ Ċ } Ċ Ċ private Ġfun Ġadapt ( aggregate Id : ĠString , Ġit : ĠAggregate Dto ): ĠAggregate Ġ{ Ċ ĉ var Ġsnapshot : ĠSnapshot ? Ġ= Ġnull Ċ ĉ if Ġ( it . snapshot Ġ!= Ġnull ) Ġ{ Ċĉ ĉ snapshot Ġ= ĠSnapshot ( it . snapshot !!. version , ĠBinary ( it . snapshot !!. data !!. payload )) Ċ ĉ } Ċ ĉ return ĠAggregate ( Ċĉ ĉ it . aggregate Type , Ċĉ ĉ snapshot , Ċĉ ĉ it . version , Ċĉ ĉ it . events . map Ġ{ Ġevent Ġ-> Ċĉĉ ĉ Event Payload ( Ċĉĉĉ ĉ aggregate Id , Ċĉĉĉ ĉ event . kind , Ċĉĉĉ ĉ event . timestamp , Ċĉĉĉ ĉ event . identity Id , Ċĉĉĉ ĉ Binary ( event . payload ) Ċĉĉ ĉ ) Ċĉ ĉ } Ċ ĉ ) Ċ } Ċ Ċ internal Ġdata Ġclass ĠGetAll Events Response Dto ( Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġevents : ĠList < Indexed Event Dto >, Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġread Direction : ĠString ?, Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġnext Position : ĠLong ? Ċ ) Ġ: ĠGeneric Json () Ġ{ Ċ ĉ @ Suppress (" UNUSED ") Ċ ĉ constructor () Ġ: Ġthis ( mutable ListOf (), Ġnull , Ġ 0 L ) Ċ } Ċ Ċ internal Ġdata Ġclass ĠIndexed Event Dto ( Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġposition : ĠLong , Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġtenant : ĠString , Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġaggregate Type : ĠString , Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġversion : ĠLong , Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġpayload : ĠEvent Payload Dto Ċ ) Ġ: ĠGeneric Json () Ġ{ Ċ ĉ @ Suppress (" UNUSED ") Ċ ĉ constructor () Ġ: Ġthis ( 0 L , Ġ"", Ġ"", Ġ 0 L , ĠEvent Payload Dto ("", Ġ 0 L , Ġ"", Ġ"")) Ċ } ĊĊ Ċ internal Ġdata Ġclass ĠGet Events Response Dto (@ Key Ġ@ Jvm Field Ġvar Ġaggreg ates : ĠList < Aggregate Dto >) Ġ: ĠGeneric Json () Ġ{ Ċ ĉ @ Suppress (" UNUSED ") Ċ ĉ constructor () Ġ: Ġthis ( mutable ListOf ()) Ċ } Ċ Ċ internal Ġdata Ġclass ĠAggregate Dto ( Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġaggregate Type : ĠString , Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġsnapshot : ĠSnapshot Dto ?, Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġversion : ĠLong , Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġtopic : ĠString , Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġevents : ĠList < Event Payload Dto > Ċ ) Ġ{ Ċ ĉ constructor () Ġ: Ġthis ("", Ġnull , Ġ 0 L , Ġ"", ĠlistOf ()) Ċ } Ċ Ċ internal Ġdata Ġclass ĠEvent Payload Dto ( Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġkind : ĠString , Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġtimestamp : ĠLong , Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġidentity Id : ĠString , Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġpayload : ĠString Ċ ) Ġ: ĠGeneric Json () Ġ{ Ċ ĉ @ Suppress (" UNUSED ") Ċ ĉ constructor () Ġ: Ġthis ("", Ġ 0 L , Ġ"", Ġ"") Ċ } Ċ Ċ internal Ġdata Ġclass ĠSave Events Request Dto ( Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġaggregate Id : ĠString , Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġaggregate Type : ĠString , Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġversion : ĠLong , Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġtopic Name : ĠString , Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġevents : ĠList < Event Payload Dto >, Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġsnapshot Required : ĠBoolean , Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġsnapshot : ĠSnapshot Dto ? Ċ ) Ġ: ĠGeneric Json () Ġ{ Ċ ĉ @ Suppress (" UNUSED ") Ċ ĉ constructor () Ġ: Ġthis ("", Ġ"", Ġ 0 L , Ġ"", Ġmutable ListOf (), Ġfalse , Ġnull ) Ċ } Ċ Ċ internal Ġdata Ġclass ĠSave Events Response Dto ( Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġaggregate Id : ĠString , Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġversion : ĠLong , Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġsequence Ids : ĠList < Long >, Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġaggregate : ĠAggregate Dto Ċ ) Ġ: ĠGeneric Json () Ġ{ Ċ ĉ @ Suppress (" UNUSED ") Ċ ĉ constructor () Ġ: Ġthis ("", Ġ 0 L , ĠlistOf (), ĠAggregate Dto ()) Ċ } Ċ Ċ internal Ġdata Ġclass ĠRe vert Events Request Dto (@ Key Ġ@ Jvm Field Ġvar Ġaggregate Id : ĠString , Ġ@ Key Ġ@ Jvm Field Ġvar Ġcount : ĠInt ) Ġ: Ċ ĉ Generic Json () Ġ{ Ċ ĉ @ Suppress (" UNUSED ") Ċ ĉ constructor () Ġ: Ġthis ("", Ġ 0 ) Ċ } Ċ Ċ internal Ġdata Ġclass ĠSnapshot Required Dto ( Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġcurrent Events : ĠList < Event Payload Dto >, Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġcurrent Snapshot : ĠSnapshot Dto ? Ġ= Ġnull , Ċ ĉ @ Key Ġ@ Jvm Field Ġvar Ġversion : ĠLong Ċ ) Ġ: ĠGeneric Json () Ġ{ Ċ ĉ @ Suppress (" UNUSED ") Ċ ĉ constructor () Ġ: Ġthis ( listOf (), Ġnull , Ġ 0 L ) Ċ } Ċ Ċ internal Ġdata Ġclass ĠSnapshot Dto (@ Key Ġ@ Jvm Field Ġvar Ġversion : ĠLong , Ġ@ Key Ġ@ Jvm Field Ġvar Ġdata : ĠBinary Dto ?) Ġ: ĠGeneric Json () Ġ{ Ċ ĉ @ Suppress (" UNUSED ") Ċ ĉ constructor () Ġ: Ġthis ( 0 , Ġnull ) Ċ } Ċ Ċ internal Ġdata Ġclass ĠBinary Dto (@ Key Ġ@ Jvm Field Ġvar Ġpayload : ĠByteArray ) Ġ: ĠGeneric Json () Ġ{ Ċ ĉ override Ġfun Ġequals ( other : ĠAny ?): ĠBoolean Ġ{ Ċĉ ĉ if Ġ( this Ġ=== Ġother ) Ġreturn Ġtrue Ċĉ ĉ if Ġ( java Class Ġ!= Ġother ?. java Class ) Ġreturn Ġfalse Ċĉ ĉ if Ġ(! super . equals ( other )) Ġreturn Ġfalse ĊĉĉĊĉ ĉ other Ġas ĠBinary Dto ĊĉĉĊĉ ĉ if Ġ(! Arrays . equals ( payload , Ġother . payload )) Ġreturn Ġfalse ĊĉĉĊĉ ĉ return Ġtrue Ċ ĉ } ĊĉĊ ĉ override Ġfun ĠhashCode (): ĠInt Ġ{ Ċĉ ĉ var Ġresult Ġ= Ġsuper . hashCode () Ċĉ ĉ result Ġ= Ġ 3 1 Ġ* Ġresult Ġ+ ĠArrays . hashCode ( payload ) Ċĉ ĉ return Ġresult Ċ ĉ } ĊĉĊ ĉ @ Suppress (" UNUSED ") Ċ ĉ constructor () Ġ: Ġthis ( ByteArray ( 0 )) Ċ } ĊĊ