1
1
mirror of https://github.com/wader/fq.git synced 2024-11-25 23:13:19 +03:00

Merge pull request #995 from wader/binary-each

intepr: Support each for binary values
This commit is contained in:
Mattias Wadman 2024-08-21 16:23:47 +02:00 committed by GitHub
commit 2a9dc432c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 3 deletions

View File

@ -405,8 +405,9 @@ There is also `tobitsrange` and `tobytesrange` which does the same thing but wil
- `[0x12, 0x34, 0x56] | tobits[4:12]` will be a binary with the byte `0x23`
- `[0x12, 0x34, 0x56] | tobits[4:20]` will be a binary with the byte `0x23`, `0x45`
- `[0x12, 0x34, 0x56] | tobits[4:20] | tobytes[1:]` will be a binary with the byte `0x45`,
Both `.[index]` and `.[start:end]` support negative indices to index from end.
- Both `.[index]` and `.[start:end]` support negative indices to index from end.
- `.[]` outputs all bytes or bit as integers, same as `explode[]`.
- `explode` output an array with all byte or bits as integers, same as `[.[]]`.
#### Binary array

View File

@ -414,7 +414,12 @@ func (b Binary) JQValueKey(name string) any {
return nil
}
func (b Binary) JQValueEach() any {
return nil
l := int(b.r.Len / int64(b.unit))
vs := make([]gojq.PathValue, l)
for i := 0; i < l; i++ {
vs[i] = gojq.PathValue{Path: i, Value: b.JQValueIndex(i)}
}
return vs
}
func (b Binary) JQValueType() string {
return gojq.JQTypeString