extend transferrer protocol to send progress bar total size updates

New protocol is not back-compat with old one, but it's never been
released so that's ok.
This commit is contained in:
Joey Hess 2020-12-11 12:39:00 -04:00
parent 94b323a8e8
commit 095cdc7e83
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
6 changed files with 44 additions and 22 deletions

View file

@ -68,10 +68,11 @@ newMessageState = do
data SerializedOutput
= OutputMessage S.ByteString
| OutputError String
| StartProgressMeter (Maybe TotalSize)
| BeginProgressMeter (Maybe TotalSize)
| UpdateProgressMeter BytesProcessed
| UpdateProgressMeterTotalSize TotalSize
| EndProgressMeter
| StartPrompt
| BeginPrompt
| EndPrompt
| JSONObject L.ByteString
-- ^ This is always sent, it's up to the consumer to decide if it

View file

@ -85,16 +85,18 @@ instance Proto.Sendable TransferResponse where
["om", Proto.serialize (encode_c (decodeBS m))]
formatMessage (TransferOutput (OutputError e)) =
["oe", Proto.serialize (encode_c e)]
formatMessage (TransferOutput (StartProgressMeter (Just (TotalSize n)))) =
["ops", Proto.serialize n]
formatMessage (TransferOutput (StartProgressMeter Nothing)) =
["opsx"]
formatMessage (TransferOutput (BeginProgressMeter (Just (TotalSize n)))) =
["opb", Proto.serialize n]
formatMessage (TransferOutput (BeginProgressMeter Nothing)) =
["opbx"]
formatMessage (TransferOutput (UpdateProgressMeter n)) =
["op", Proto.serialize n]
formatMessage (TransferOutput (UpdateProgressMeterTotalSize (TotalSize sz))) =
["ops", Proto.serialize sz]
formatMessage (TransferOutput EndProgressMeter) =
["ope"]
formatMessage (TransferOutput StartPrompt) =
["oprs"]
formatMessage (TransferOutput BeginPrompt) =
["oprb"]
formatMessage (TransferOutput EndPrompt) =
["opre"]
formatMessage (TransferOutput (JSONObject b)) =
@ -109,16 +111,18 @@ instance Proto.Receivable TransferResponse where
TransferOutput . OutputMessage . encodeBS . decode_c
parseCommand "oe" = Proto.parse1 $
TransferOutput . OutputError . decode_c
parseCommand "ops" = Proto.parse1 $
TransferOutput . StartProgressMeter . Just . TotalSize
parseCommand "opsx" = Proto.parse0 $
TransferOutput (StartProgressMeter Nothing)
parseCommand "opb" = Proto.parse1 $
TransferOutput . BeginProgressMeter . Just . TotalSize
parseCommand "opbx" = Proto.parse0 $
TransferOutput (BeginProgressMeter Nothing)
parseCommand "op" = Proto.parse1 $
TransferOutput . UpdateProgressMeter
parseCommand "ops" = Proto.parse1 $
TransferOutput . UpdateProgressMeterTotalSize . TotalSize
parseCommand "ope" = Proto.parse0 $
TransferOutput EndProgressMeter
parseCommand "oprs" = Proto.parse0 $
TransferOutput StartPrompt
parseCommand "oprb" = Proto.parse0 $
TransferOutput BeginPrompt
parseCommand "opre" = Proto.parse0 $
TransferOutput EndPrompt
parseCommand "oj" = Proto.parse1 $