Skip to content

Commit a59fd16

Browse files
committed
Add support for size CtlOp and bounds.
1 parent b7d874c commit a59fd16

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

cuddle.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 3.4
22
name: cuddle
3-
version: 0.1.6.0
3+
version: 0.1.7.0
44
synopsis: CDDL Generator and test utilities
55

66
-- description:

src/Codec/CBOR/Cuddle/CBOR/Gen.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,22 @@ genForCTree (CTree.Control op target controller) = do
277277
CTree.Postlude PTBytes -> S . TBytes <$> genBytes (fromIntegral n)
278278
CTree.Postlude PTUInt -> S . TInteger <$> genUniformRM (0, 2 ^ n - 1)
279279
_ -> error "Cannot apply size operator to target "
280+
(CtlOp.Size, CTree.Range {CTree.from, CTree.to}) -> do
281+
f <- resolveIfRef from
282+
t <- resolveIfRef to
283+
case (f, t) of
284+
(CTree.Literal (VUInt f1), CTree.Literal (VUInt t1)) -> case tt of
285+
CTree.Postlude PTBytes ->
286+
genUniformRM (fromIntegral f1, fromIntegral t1)
287+
>>= (fmap (S . TBytes) . genBytes)
288+
CTree.Postlude PTUInt ->
289+
S . TInteger
290+
<$> genUniformRM (fromIntegral f1, fromIntegral t1)
291+
_ -> error $ "Cannot apply size operator to target: " <> show tt
292+
_ ->
293+
error $
294+
"Invalid controller for .size operator: "
295+
<> show controller
280296
(CtlOp.Size, _) ->
281297
error $
282298
"Invalid controller for .size operator: "

0 commit comments

Comments
 (0)