Movatterモバイル変換
[0]ホーム
modulePostgreSQL.Binary.Decoder(Decoder,run,int,float4,float8,bool,bytea_strict,bytea_lazy,text_strict,text_lazy,char,fn,numeric,uuid,json_ast,json_bytes,jsonb_ast,jsonb_bytes,date,time_int,time_float,timetz_int,timetz_float,timestamp_int,timestamp_float,timestamptz_int,timestamptz_float,interval_int,interval_float,ArrayDecoder,array,arrayDimension,arrayValue,arrayNonNullValue,CompositeDecoder,composite,compositeValue,compositeNonNullValue,hstore,enum,)whereimportPostgreSQL.Binary.Preludehiding(take,bool,drop,state,fail,failure)importBinaryParserimportqualifiedPostgreSQL.Binary.DataasDataimportqualifiedPostgreSQL.Binary.IntegralasIntegralimportqualifiedPostgreSQL.Binary.IntervalasIntervalimportqualifiedPostgreSQL.Binary.NumericasNumericimportqualifiedPostgreSQL.Binary.TimeasTimeimportqualifiedData.VectorasVectorimportqualifiedData.ByteStringasByteStringimportqualifiedData.ByteString.LazyasLazyByteStringimportqualifiedData.TextasTextimportqualifiedData.Text.EncodingasTextimportqualifiedData.Text.Encoding.ErrorasTextimportqualifiedData.Text.Lazy.EncodingasLazyTextimportqualifiedData.UUIDasUUIDimportqualifiedData.AesonasAesontypeDecoder=BinaryParserintOfSize::(Integrala,Bitsa)=>Int->DecoderaintOfSizex=fmapIntegral.pack(bytesOfSizex)onContent::Decodera->Decoder(Maybea)onContentdecoder=intOfSize4>>=\case(1)->pureNothingn->fmapJust(sizedndecoder)content::Decoder(MaybeByteString)content=intOfSize4>>=\case(1)->pureNothingn->fmapJust(bytesOfSizen)nonNull::Maybea->DecoderanonNull=maybe(failure"Unexpected NULL")returnfn::(ByteString->EitherTexta)->Decoderafnfn=BinaryParser.remainders>>=eitherBinaryParser.failurereturn.fnint::(Integrala,Bitsa)=>Decoderaint=fmapIntegral.packremaindersfloat4::DecoderFloatfloat4=unsafeCoerce(int::DecoderInt32)float8::DecoderDoublefloat8=unsafeCoerce(int::DecoderInt64)bool::DecoderBoolbool=fmap(==1)bytenumeric::DecoderScientificnumeric=docomponentsAmount<-intOfSize2pointIndex<-intOfSize2signCode<-intOfSize2unitOfSize2components<-Vector.replicateMcomponentsAmount(intOfSize2)eitherfailurereturn(Numeric.scientificpointIndexsignCodecomponents)uuid::DecoderUUIDuuid=UUID.fromWords<$>intOfSize4<*>intOfSize4<*>intOfSize4<*>intOfSize4json_ast::DecoderAeson.Valuejson_ast=bytea_strict>>=either(BinaryParser.failure.fromString)pure.Aeson.eitherDecodeStrict'json_bytes::(ByteString->EitherTexta)->Decoderajson_bytescont=getAllBytes>>=parseJSONwheregetAllBytes=BinaryParser.remaindersparseJSON=eitherBinaryParser.failurereturn.contjsonb_ast::DecoderAeson.Valuejsonb_ast=jsonb_bytes$mapLeftfromString.Aeson.eitherDecodeStrict'jsonb_bytes::(ByteString->EitherTexta)->Decoderajsonb_bytescont=getAllBytes>>=trimBytes>>=parseJSONwheregetAllBytes=BinaryParser.remainderstrimBytes=maybe(BinaryParser.failure"Empty input")return.fmapsnd.ByteString.unconsparseJSON=eitherBinaryParser.failurereturn.contchar::DecoderCharchar=fmapText.unconstext_strict>>=\caseJust(c,"")->returncNothing->failure"Empty input"_->failure"Consumed too much"text_strict::DecoderTexttext_strict=remainders>>=either(failure.exception)return.Text.decodeUtf8'whereexception=\caseText.DecodeErrormessagebyte->fromStringmessage_->$bug"Unexpected unicode exception"text_lazy::DecoderLazyTexttext_lazy=bytea_lazy>>=either(failure.exception)return.LazyText.decodeUtf8'whereexception=\caseText.DecodeErrormessagebyte->fromStringmessage_->$bug"Unexpected unicode exception"bytea_strict::DecoderByteStringbytea_strict=remaindersbytea_lazy::DecoderLazyByteStringbytea_lazy=fmapLazyByteString.fromStrictremaindersdate::DecoderDaydate=fmap(Time.postgresJulianToDay.fromIntegral)(int::DecoderInt32)time_int::DecoderTimeOfDaytime_int=fmapTime.microsToTimeOfDayinttime_float::DecoderTimeOfDaytime_float=fmapTime.secsToTimeOfDayfloat8timetz_int::Decoder(TimeOfDay,TimeZone)timetz_int=(,)<$>sized8time_int<*>tztimetz_float::Decoder(TimeOfDay,TimeZone)timetz_float=(,)<$>sized8time_float<*>tztz::DecoderTimeZonetz=fmap(minutesToTimeZone.negate.(flipdiv60).fromIntegral)(int::DecoderInt32)timestamp_int::DecoderLocalTimetimestamp_int=fmapTime.microsToLocalTimeinttimestamp_float::DecoderLocalTimetimestamp_float=fmapTime.secsToLocalTimefloat8timestamptz_int::DecoderUTCTimetimestamptz_int=fmapTime.microsToUTCinttimestamptz_float::DecoderUTCTimetimestamptz_float=fmapTime.secsToUTCfloat8interval_int::DecoderDiffTimeinterval_int=dou<-sized8intd<-sized4intm<-intreturn$Interval.toDiffTime$Interval.Intervaludminterval_float::DecoderDiffTimeinterval_float=dou<-sized8(fmap(round.(*(10^6)).toRational)float8)d<-sized4intm<-intreturn$Interval.toDiffTime$Interval.IntervaludmarrayRep::DecoderData.ArrayarrayRep=dodimensionsAmount<-intOfSize4nullsValue<-nullsoid<-intOfSize4dimensions<-Vector.replicateMdimensionsAmountdimensionletvaluesAmount=(Vector.product.Vector.mapfst)dimensionsvalues<-Vector.replicateM(fromIntegralvaluesAmount)contentreturn(dimensions,values,nullsValue,oid)wheredimension=(,)<$>intOfSize4<*>intOfSize4nulls=intOfSize4>>=\(x::Word32)->casexof0->returnFalse1->returnTruew->failure$"Invalid value: "<>(fromString.show)wcompositeRep::DecoderData.CompositecompositeRep=docomponentsAmount<-intOfSize4Vector.replicateMcomponentsAmountcomponentwherecomponent=(,)<$>intOfSize4<*>contenthstore::(forallm.Monadm=>Int->m(k,Maybev)->mr)->Decoderk->Decoderv->DecoderrhstorereplicateMkeyContentvalueContent=docomponentsAmount<-intOfSize4replicateMcomponentsAmountcomponentwherecomponent=(,)<$>key<*>valuewherekey=onContentkeyContent>>=nonNullvalue=onContentvalueContenthstoreRep::DecoderData.HStorehstoreRep=docomponentsAmount<-intOfSize4Vector.replicateMcomponentsAmountcomponentwherecomponent=(,)<$>key<*>contentwherekey=intOfSize4>>=bytesOfSizenewtypeCompositeDecodera=CompositeDecoder(Decodera)deriving(Functor,Applicative,Monad)composite::CompositeDecodera->Decoderacomposite(CompositeDecoderdecoder)=unitOfSize4*>decodercompositeValue::Decodera->CompositeDecoder(Maybea)compositeValue=CompositeDecoder.onContentcompositeNonNullValue::Decodera->CompositeDecoderacompositeNonNullValue=CompositeDecoder.join.fmap(maybe(failure"Unexpected NULL")return).onContentnewtypeArrayDecodera=ArrayDecoder([Word32]->Decodera)deriving(Functor)array::ArrayDecodera->Decoderaarray(ArrayDecoderdecoder)=dodimensionsAmount<-intOfSize4unitOfSize(4+4)dimensionSizes<-replicateMdimensionsAmountdimensionSizedecoderdimensionSizeswheredimensionSize=intOfSize4<*unitOfSize4arrayDimension::(forallm.Monadm=>Int->ma->mb)->ArrayDecodera->ArrayDecoderbarrayDimensionreplicateM(ArrayDecodercomponent)=ArrayDecoder$\casehead:tail->replicateM(fromIntegralhead)(componenttail)_->failure"A missing dimension length"arrayValue::Decodera->ArrayDecoder(Maybea)arrayValue=ArrayDecoder.const.onContentarrayNonNullValue::Decodera->ArrayDecoderaarrayNonNullValue=ArrayDecoder.const.join.fmap(maybe(failure"Unexpected NULL")return).onContentenum::(Text->Maybea)->Decoderaenummapping=text_strict>>=onTextwhereonTexttext=maybeonNothingonJust(mappingtext)whereonNothing=failure("No mapping for text \""<>text<>"\"")onJust=pure
[8]ページ先頭