Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
duk_util_bitdecoder.c File Reference
#include "duk_internal.h"

Go to the source code of this file.

Functions

DUK_INTERNAL duk_int32_t duk_bd_decode (duk_bitdecoder_ctx *ctx, duk_small_int_t bits)
 
DUK_INTERNAL duk_small_int_t duk_bd_decode_flag (duk_bitdecoder_ctx *ctx)
 
DUK_INTERNAL duk_int32_t duk_bd_decode_flagged (duk_bitdecoder_ctx *ctx, duk_small_int_t bits, duk_int32_t def_value)
 

Function Documentation

◆ duk_bd_decode()

DUK_INTERNAL duk_int32_t duk_bd_decode ( duk_bitdecoder_ctx * ctx,
duk_small_int_t bits )

Definition at line 11 of file duktape-1.5.2/src-separate/duk_util_bitdecoder.c.

11 {
12 duk_small_int_t shift;
13 duk_uint32_t mask;
14 duk_uint32_t tmp;
15
16 /* Note: cannot read more than 24 bits without possibly shifting top bits out.
17 * Fixable, but adds complexity.
18 */
19 DUK_ASSERT(bits >= 1 && bits <= 24);
20
21 while (ctx->currbits < bits) {
22#if 0
23 DUK_DDD(DUK_DDDPRINT("decode_bits: shift more data (bits=%ld, currbits=%ld)",
24 (long) bits, (long) ctx->currbits));
25#endif
26 ctx->currval <<= 8;
27 if (ctx->offset < ctx->length) {
28 /* If ctx->offset >= ctx->length, we "shift zeroes in"
29 * instead of croaking.
30 */
31 ctx->currval |= ctx->data[ctx->offset++];
32 }
33 ctx->currbits += 8;
34 }
35#if 0
36 DUK_DDD(DUK_DDDPRINT("decode_bits: bits=%ld, currbits=%ld, currval=0x%08lx",
37 (long) bits, (long) ctx->currbits, (unsigned long) ctx->currval));
38#endif
39
40 /* Extract 'top' bits of currval; note that the extracted bits do not need
41 * to be cleared, we just ignore them on next round.
42 */
43 shift = ctx->currbits - bits;
44 mask = (1 << bits) - 1;
45 tmp = (ctx->currval >> shift) & mask;
46 ctx->currbits = shift; /* remaining */
47
48#if 0
49 DUK_DDD(DUK_DDDPRINT("decode_bits: %ld bits -> 0x%08lx (%ld), currbits=%ld, currval=0x%08lx",
50 (long) bits, (unsigned long) tmp, (long) tmp, (long) ctx->currbits, (unsigned long) ctx->currval));
51#endif
52
53 return tmp;
54}
#define mask(n)

References duk_bitdecoder_ctx::currbits, duk_bitdecoder_ctx::currval, duk_bitdecoder_ctx::data, DUK_ASSERT, DUK_DDD, DUK_DDDPRINT, duk_bitdecoder_ctx::length, mask, and duk_bitdecoder_ctx::offset.

Referenced by duk_bd_decode_flag(), and duk_bd_decode_flagged().

◆ duk_bd_decode_flag()

DUK_INTERNAL duk_small_int_t duk_bd_decode_flag ( duk_bitdecoder_ctx * ctx)

Definition at line 56 of file duktape-1.5.2/src-separate/duk_util_bitdecoder.c.

56 {
57 return (duk_small_int_t) duk_bd_decode(ctx, 1);
58}
DUK_INTERNAL duk_int32_t duk_bd_decode(duk_bitdecoder_ctx *ctx, duk_small_int_t bits)

References duk_bd_decode().

Referenced by duk_bd_decode_flagged().

◆ duk_bd_decode_flagged()

DUK_INTERNAL duk_int32_t duk_bd_decode_flagged ( duk_bitdecoder_ctx * ctx,
duk_small_int_t bits,
duk_int32_t def_value )

Definition at line 64 of file duktape-1.5.2/src-separate/duk_util_bitdecoder.c.

64 {
65 if (duk_bd_decode_flag(ctx)) {
66 return (duk_int32_t) duk_bd_decode(ctx, bits);
67 } else {
68 return def_value;
69 }
70}
DUK_INTERNAL duk_small_int_t duk_bd_decode_flag(duk_bitdecoder_ctx *ctx)

References duk_bd_decode(), and duk_bd_decode_flag().