-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Literal "byte arrays" and "true arrays of integers" #371
Comments
How about |
I guess we don't need any heuristics, the type is determined by context. In If we need Something like seq:
- id: a
type: int_s(_index)
repeat: eos
types:
s:
seq:
- id: a
type: u4
- id: b
type: f4
int_s:
params:
- id: n
type: u4
seq:
- id: a
content:
#only a single child from a restricted set of keys is allowed, if it is an object
serialize: # in this case there is no need to really serialize, you can parse and compare, the compiler should catch this and generate the appropriate code.
#only a single child is allowed, the key is the name of type to serialize, the value is an object with names of properties as tkeys and values to assign as values
s:
a: n
b: n.to_f4 |
In Construct, Const value is not necessarily bytes type. Something like @GreyCat You asked for example of usecase for thin-seq, what if the user wanted something like - id: a
content: [1,2,3]
type: u1
repeat: expr
repeat-expr: 3 |
I'd prefer a solution which still uses YAML schema. So while So I'd introduce a new property which contains the type (eg. in the form Another option maybe using YAML tags, but to be frank I am not sure that it's easy to add custom types to various YAML parsers, and it would give the schema users a less out-of-box experience, so I'd still prefer the It's a harder question for expressions, but I presume we could use the current cast operator? Or introduce something new? |
I agree. Did you mean - id: a
content: [1,2,3]
content-type: u4 |
@KOLANICH @koczkatamas Guys, this question is about literals, and I'm talking about expression language. So, there is no YAML, no KSY tags, nothing, just a string. For practical purposes, you can think of it as a string that we embed into instances:
foo:
value: '[1, 2, 3]' # <= here
Yeah, good idea. We do casting as postfix operator
The same operator could be actually used to specify sized literals, if we'll ever need it — i.e. |
I wonder if we really need such kind of literals. I mean that usually we deal with arrays of structures, not arrays of numbers. Using literal array syntax doesn't suit the use case with structs well. But if we had a syntax with structs there should be no need for a separate syntax with numbers since we use it very seldom. |
Yes, we do — at least for #253, and it's also widely used for stuff like "construct byte array from expressions, then convert it to string". |
- actual: docs[0].indicator #the type is defined by the type of this field (if there is no selection of type based on something, but if there is, you can test the type of the switch-on variable or maybe introduce some property to get a type), there is no need to specify it explicitly
expected: '[0x49, 0x49]'
my proposal fits here (assumming serialization, chains and assertions implemented). Of course it is wery rough and needs some improvement before implementation. |
Seems to be working now, relevant tests added to TranslatorSpec, usable for KST purposes. |
Currently, we have single syntax to specify both "byte arrays" and "true arrays". Distinction is done by compiler with some heuristics:
[1, 2, 3]
would be byte array (because all elements are integer literals 0..255)[1, 2, 3, 500]
would be true array (because 500 > 255)[0 + 1, 2, 3]
would be true array (because0 + 1
is not a literal)I propose to get rid of this heuristics and make an uniform & easy-to-understand way to specify both.
This is (kind of) prerequisite for #253. Technically we can (and will) use hacky trick with
0 + 1
, but it's much better to have clear specs.The text was updated successfully, but these errors were encountered: