Skip to content

Make Value's flat/cbor decoder consistent with unValueData#7669

Open
zliu41 wants to merge 1 commit intomasterfrom
zliu41/decodevalue
Open

Make Value's flat/cbor decoder consistent with unValueData#7669
zliu41 wants to merge 1 commit intomasterfrom
zliu41/decodevalue

Conversation

@zliu41
Copy link
Member

@zliu41 zliu41 commented Mar 16, 2026

Factored out helper function buildValueWith, which is used by all three. Fixes #7602

@zliu41 zliu41 requested a review from a team March 16, 2026 19:09
@zliu41 zliu41 added the No Changelog Required Add this to skip the Changelog Check label Mar 16, 2026
Copy link
Collaborator

@SeungheonOh SeungheonOh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I noticed some change in behavior but looks like those are intended and I think new behaviors are better.

innerLen <- CBOR.decodeMapLen
inner <- replicateM innerLen ((,) <$> CBOR.decode <*> CBOR.decode)
pure (currency, inner)
buildValueWith "Value CBOR decoder" pure pure outer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have slight change in behavior here I think. Previously pack was used which would've normalized and allowed not-normal values to be parsed. However, buildValueWith will fail if non-normal value is given.

I think this is a better behavior. Just making a note.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. realized this is intended after reading the new test cases. Seems good.

( \(cData, tsData) ->
(,)
<$> unB cData
<*> case tsData of Map ts -> pure ts; _ -> fail "unValueData: non-Map constructor"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick : we can probably have unMap here instead of ugly single line case

| i == 0 || i < unQuantity minBound || i > unQuantity maxBound ->
fail "unValueData: invalid quantity"
| otherwise -> pure (UnsafeQuantity i)
| Just q <- quantity i -> pure q
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quantity won't ensure i /= 0 which is invalid quantity here(unless we want to change behavior of unValueData)

buildValueWith handles this correctly.

<> show (unQuantity x)
Just q -> pure q

buildValueWith
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

documentation about what this function actually enforces/when it fails would be nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

No Changelog Required Add this to skip the Changelog Check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Value serialization is overallocating, Value deserialization is superlinear and stupid

2 participants