You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And even having to do similar things to work with [..bytes] to 'join' it into a normal 'bytes' type, eg concatenating the list.
It's workable, but it feels very awkward. I also think runes, might be interpreted differently from a raw length, but I want to work with just bytes or ideally [...byte] by that doesn't seem to exist
So my two questions
How to constrain data:bytes, to have a specific length?
How to concatenate [...bytes] into a single bytes instance?
I found that there is a uint8 constraint, so [...uint8] would mean list.Concat works, but can we create bytes from [...uint8]?
Update 1: Ah uint8, is non ideal, it's a bigger int, constant to a uint8, but converting that adds extra stuff
import "strings"
#data: [...bytes]
let strs = [for d in #data { "\(d)"}]
let str= strings.Join(strs,"")
let output = strings.ByteSlice(str,0,len(str))
data: output
data: bytes
if len(data) != 6 {
data: "data length mismatch \(len(data)) != 10"
}
#data: ['\x48','\x65','\x6C\x6C\x6F']
but probably suffers from
I am abusing the string conversions still,
I feel like using string as an error message is awkward. I did try to define 'bottom' | if Len is unexpected, however you can't provide any user context to that, its just 'error', it would be nice to specify hey the input is incorrect, especially in more complex data structures. Is it possible to add context/messages to a bottom type?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Is there any way of constraining the bytes type?, it seems mainly a stand-in for string, but there's no clear way to restrict or constrain it easily.
At the moment I have found I can hack it into strings, then use the strings definitions to work with it.
Eg https://cuelang.org/play/?id=ijXnA8UOWSm#w=function&i=cue&f=eval&o=cue
And even having to do similar things to work with [..bytes] to 'join' it into a normal 'bytes' type, eg concatenating the list.
It's workable, but it feels very awkward. I also think runes, might be interpreted differently from a raw length, but I want to work with just bytes or ideally [...byte] by that doesn't seem to exist
So my two questions
Update 1: Ah uint8, is non ideal, it's a bigger int, constant to a uint8, but converting that adds extra stuff
https://cuelang.org/play/?id=EGkAFUwlJKI#w=function&i=cue&f=eval&o=cue
Is a bit of the way, for 2, though it feels weird to go 'via' strings to 'Join', lists of bytes
Update: 2
Okay so 1 and 2 is maybe workable here
https://cuelang.org/play/?id=kn8MP-PGOyQ#w=function&i=cue&f=eval&o=cue
but probably suffers from
Beta Was this translation helpful? Give feedback.
All reactions