Repository navigation
Conversation
mvo5
force-pushed
the
yaml-unmarshal-via-json-2
branch
2 times, most recently
from
March 25, 2025 16:33
f6f97e1 to
eb6e5d9
Compare
supakeen
previously approved these changes
Mar 26, 2025
achilleas-k
reviewed
Mar 27, 2025
achilleas-k
left a comment
Member
There was a problem hiding this comment.
LGTM. Typo in error message though.
This commit adds support to load payloads for LUKS/LVM via
json/yaml. This is needed for PR#1339 where we extract the
partition tables into YAML. We have nested LUKS/LVM partitions
in e.g. the iot simplified installer.
This sadly involves some duplicated code in the Partition,
LUKSContainer, LVMLogicalVolume `UnmarshalJSON()` code.
Ideally we would write somethign like:
```go
func payloadUnmarshaller[T any](data []byte) (*T, error) {
type alias T
var withoutPayload struct {
alias
Payload json.RawMessage `json:"payload"`
PayloadType string `json:"payload_type"`
}
if err := jsonUnmarshalStrict(data, &withoutPayload); err != nil {
return nil, fmt.Errorf("cannot unmarshal %q: %w", data, err)
}
t := T(withoutPayload.alias)
payload, err := unmarshalJSONPayload(data)
t.Payload = payload
return payload, err
}
func (lv *LVMLogicalVolume) UnmarshalJSON(data []byte) (err error) {
*lv, err = payloadUnmarshaller[*LVMLogicalVolume](data)
return err
}
```
but GO does not let us and sadly its pretty fundamental:
```
./lvm.go:248:13: cannot use a type parameter as RHS in type declaration
```
and without type aliases in the custom unmarshaler we run into
an infinite recursion. So unless go supports this we will have to
live with the duplication.
mvo5
force-pushed
the
yaml-unmarshal-via-json-2
branch
from
March 27, 2025 12:01
eb6e5d9 to
c8bb6e4
Compare
achilleas-k
approved these changes
Mar 27, 2025
Contributor
Author
|
This got merged as part of #1362 so closing it here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[split out of https://github.com//pull/1339]
This commit adds support to load payloads for LUKS/LVM via
json/yaml. This is needed for PR#1339 where we extract the
partition tables into YAML. We have nested LUKS/LVM partitions
in e.g. the iot simplified installer.
This sadly involves some duplicated code in the Partition,
LUKSContainer, LVMLogicalVolume
UnmarshalJSON()code.Ideally we would write somethign like:
but GO does not let us and sadly its pretty fundamental:
and without type aliases in the custom unmarshaler we run into
an infinite recursion. So unless go supports this we will have to
live with the duplication.