Maximilian Gaß

Results 72 comments of Maximilian Gaß

But also, do I understand correctly that if I do `json.Marshal({data})`, I can make it behave consistently, because toposort information will always be lost? If so, that would be a...

An explicit unification can apparently also be used to lose toposort information? ``` o: cm: data: b: "2" o: cm: data: a: "1" one: o.cm.data two: o.cm.data & _ ```...

> I would put that in the category of "very unfortunate hack", but given that I don't know of any way for you to otherwise specify the order of fields...

My workaround doesn’t use JSON for the hashing, so that’s not a problem. The problem is if one of the values in the struct that is hashed is a JSON-marshaled...

> My workaround doesn’t use JSON for the hashing, so that’s not a problem. > The problem is if one of the values in the struct that is hashed is...

[Latest iteration of the workaround](https://cuelang.org/play/?id=wLKrw6qDqkz#w=function&i=cue&f=eval&o=cue): ``` import ( "crypto/sha256" "encoding/hex" "list" "strconv" "strings" ) _hasher: { fields!: [string]: string type: *"" | string l: list.SortStrings([for k, v in fields {strconv.Quote(k)...

> And in your code, you might be able to get away without the strings.Join call - you could just compare the lists directly. The whole goal is to create...

I guess I could try to parse the inner JSON and normalize it for the hash, but it could also be YAML or TOML or whatever … But the normalization...

I am BTW not married to hashing the content like this, I just think it’s a good way to rollout config changes. Something based on time, or Git commit ID...

I also noticed this happens with yaml.Marshal, but not with json.Marshal. [The difference is in these lines in yaml.Marshal](https://github.com/cue-lang/cue/blob/0e51dbb4ea0014f8526bd61ac418df38316d67fd/pkg/encoding/yaml/manual.go#L30): ``` if err := v.Validate(cue.Concrete(true)); err != nil { return "",...