mirror of
https://github.com/wader/fq.git
synced 2024-11-23 09:56:07 +03:00
funcs: Make intdiv truncate to int
This commit is contained in:
parent
48517c7c60
commit
962d84dc68
@ -240,7 +240,14 @@ func mp4Decode(d *decode.D, in interface{}) interface{} {
|
||||
sampleSize := t.stsz[sampleNr]
|
||||
decodeSampleRange(d, t, trackSdDataFormat, "sample", int64(sampleOffset)*8, int64(sampleSize)*8, t.decodeOpts...)
|
||||
|
||||
// log.Printf("%s %d/%d %d/%d sample=%d/%d chunk=%d size=%d %d-%d\n", t.dataFormat, stscIndex, len(t.stsc), i, stscEntry.samplesPerChunk, sampleNr, len(t.stsz), chunkNr, sampleSize, sampleOffset, sampleOffset+uint64(sampleSize))
|
||||
// log.Printf("%s %d/%d %d/%d sample=%d/%d chunk=%d size=%d %d-%d\n",
|
||||
// trackSdDataFormat, stscIndex, len(t.stsc),
|
||||
// i, stscEntry.samplesPerChunk,
|
||||
// sampleNr, len(t.stsz),
|
||||
// chunkNr,
|
||||
// sampleSize,
|
||||
// sampleOffset,
|
||||
// sampleOffset+uint64(sampleSize))
|
||||
|
||||
sampleOffset += uint64(sampleSize)
|
||||
sampleNr++
|
||||
|
@ -15,9 +15,17 @@ def decode($name; $opts): _decode($name; $opts);
|
||||
def decode($name): _decode($name; {});
|
||||
def decode: _decode("probe"; {});
|
||||
|
||||
|
||||
# TODO: figure out a saner way to force int
|
||||
def _to_int: (. % (. + 1));
|
||||
|
||||
# integer division
|
||||
# inspried by https://github.com/itchyny/gojq/issues/63#issuecomment-765066351
|
||||
def intdiv($a; $b): ($a - ($a % $b)) / $b;
|
||||
def intdiv($a; $b):
|
||||
( ($a | _to_int) as $a
|
||||
| ($b | _to_int) as $b
|
||||
| ($a - ($a % $b)) / $b
|
||||
);
|
||||
|
||||
# valid jq identifier, start with alpha or underscore then zero or more alpha, num or underscore
|
||||
def _is_ident: type == "string" and test("^[a-zA-Z_][a-zA-Z_0-9]*$");
|
||||
@ -204,8 +212,6 @@ def table(colmap; render):
|
||||
|
||||
# convert number to array of bytes
|
||||
def number_to_bytes($bits):
|
||||
# TODO: figure out a saner way to force int
|
||||
def _to_int: (. % (. + 1));
|
||||
def _number_to_bytes($d):
|
||||
if . > 0 then
|
||||
. % $d, (intdiv(.; $d) | _number_to_bytes($d))
|
||||
|
@ -45,4 +45,33 @@ include "funcs";
|
||||
["1234", 2, ["12","34"]],
|
||||
["1234", 3, ["123","4"]]
|
||||
][] | . as $t | assert("\($t[0]) | chunk(\($t[1]))"; $t[2]; $t[0] | chunk($t[1])))
|
||||
,
|
||||
([
|
||||
# 0xfffffffffffffffffffffffffffffffffffffffffffff
|
||||
[1532495540865888858358347027150309183618739122183602175, 8, [
|
||||
15,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255,
|
||||
255
|
||||
]]
|
||||
][] | . as $t | assert("\($t[0]) | number_to_bytes(\($t[1]))"; $t[2]; $t[0] | number_to_bytes($t[1])))
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user