Skip to content

Commit a817370

Browse files
committed
leios-trace-hs: support indefinite length maps when decoding cbor
1 parent 785f646 commit a817370

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

cabal.project

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,11 @@ source-repository-package
6767
--sha256: WFEmGcnCdEXmo2MCC5g+C3laGjFaBnFksgHbFeAZUQo=
6868
subdir:
6969
generated
70+
71+
source-repository-package
72+
type: git
73+
location: https://github.com/well-typed/cborg.git
74+
tag: 7a4feb69bbbc09b0b29ed41ff3b9b8526e349c62
75+
--sha256: 1YE6LP4YZNATEOfZ+/USDx/sIOi9rFbHmHVn6ONDrTc=
76+
subdir:
77+
cborg-json

leios-trace-hs/src/LeiosEvents.hs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,9 @@ decodeJSONL = mapMaybe decode . BSL8.lines
144144
encodeJSONL :: [TraceEvent] -> BSL8.ByteString
145145
encodeJSONL = BSL8.unlines . map encode
146146

147-
-- | Throws exception on CBOR decoding errors, skips values that do not decode as TraceEvent.
148-
-- WARNING: seems not to be compatible with CBOR format produced by rust-sim.
149-
decodeCBOR :: BSL8.ByteString -> [TraceEvent]
150-
decodeCBOR = go
147+
-- | Generic version of @decodeCBOR@
148+
decodeCBORJSON :: FromJSON a => BSL8.ByteString -> [a]
149+
decodeCBORJSON = go
151150
where
152151
go s | BSL8.null s = []
153152
go s =
@@ -157,6 +156,11 @@ decodeCBOR = go
157156
Success x -> x : go s'
158157
Error _ -> go s'
159158

159+
-- | Throws exception on CBOR decoding errors, skips values that do not decode as TraceEvent.
160+
-- WARNING: seems not to be compatible with CBOR format produced by rust-sim.
161+
decodeCBOR :: BSL8.ByteString -> [TraceEvent]
162+
decodeCBOR = decodeCBORJSON
163+
160164
-- | Uses standard CBOR encoding of JSON values, encoded events are concatenated with no separator.
161165
encodeCBOR :: [TraceEvent] -> BSL8.ByteString
162166
encodeCBOR = BSL8.concat . map (toLazyByteString . encodeValue . toJSON)

0 commit comments

Comments
 (0)