Skip to content
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

Feature request: zero-length start/end properties #708

Closed
ksa-real opened this issue Jun 20, 2023 · 7 comments
Closed

Feature request: zero-length start/end properties #708

ksa-real opened this issue Jun 20, 2023 · 7 comments

Comments

@ksa-real
Copy link
Contributor

Allow access of start/end position of byte range-like structures via start / end read-only properties.

The properties are already present internally, so it looks like it won't break anything. Please let me know if I'm wrong.

@wader
Copy link
Owner

wader commented Jun 20, 2023

Hi, i think you can already do it if i don't misunderstand what you want to do:

$ fq '.frames[1] | tobytes, tobytesrange, tobits, tobitsrange | {start,stop,size}' doc/file.mp3
{
  "size": 208,
  "start": 0,
  "stop": 208
}
{
  "size": 208,
  "start": 2937,
  "stop": 3145
}
{
  "size": 1664,
  "start": 0,
  "stop": 1664
}
{
  "size": 1664,
  "start": 23496,
  "stop": 25160
}

So binaries has start/stop/size properties but you have to use *range function or slice to get one that is "offsetted". Just tobytes will have a zero start value.

Hope that helps and let me know if it make sense :)

@wader
Copy link
Owner

wader commented Jun 20, 2023

Maybe the discussion in #639 is interesting also

@ksa-real
Copy link
Contributor Author

Yeah, I left a comment there recently. The question is why use an extra step? Why not just .frames[1].start?

@wader
Copy link
Owner

wader commented Jun 20, 2023

Ah sorry noticed your comment now. It's possible using _start, there are some reasons these are internal and i'm a bit reluctant to document and expose them more:

  • You can do _start etc on all decode value types (number, string, array) but it becomes ambiguous what "start" means for a struct (object), is it a field "start" or the start bit range?
  • Should start, stop etc be returned by keys? at the moment all _* fields are hidden from those functions as otherwise some parts of "standard" jq will act strange, ex you probably don't want ../recurse to see them.

So the current "safe" solution is that you have to use a function. But i'm open to change this if we can come up with something that don't mess too much with how one would expect jq to behave. Some new syntax could be interesting, ideally compatible with jq, but would require maintain larger change to gojq etc.

@wader
Copy link
Owner

wader commented Jul 1, 2023

Close for now? maybe revisit in the future if some fancier syntax for "special" properties are introduces?

@ksa-real
Copy link
Contributor Author

ksa-real commented Jul 5, 2023

Yes, closing. Underscore-prefixed items are great, somehow missed them. I guess they will stay unless something else is introduced.

@ksa-real ksa-real closed this as completed Jul 5, 2023
@wader
Copy link
Owner

wader commented Jul 5, 2023

@ksa-real 👍 yeap think they will stay for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants