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

Go to the source code of this file.

Functions

DUK_INTERNAL void duk_be_encode (duk_bitencoder_ctx *ctx, duk_uint32_t data, duk_small_int_t bits)
 
DUK_INTERNAL void duk_be_finish (duk_bitencoder_ctx *ctx)
 

Function Documentation

◆ duk_be_encode()

DUK_INTERNAL void duk_be_encode ( duk_bitencoder_ctx * ctx,
duk_uint32_t data,
duk_small_int_t bits )

Definition at line 7 of file duktape-1.5.2/src-separate/duk_util_bitencoder.c.

7 {
8 duk_uint8_t tmp;
9
10 DUK_ASSERT(ctx != NULL);
11 DUK_ASSERT(ctx->currbits < 8);
12
13 /* This limitation would be fixable but adds unnecessary complexity. */
14 DUK_ASSERT(bits >= 1 && bits <= 24);
15
16 ctx->currval = (ctx->currval << bits) | data;
17 ctx->currbits += bits;
18
19 while (ctx->currbits >= 8) {
20 if (ctx->offset < ctx->length) {
21 tmp = (duk_uint8_t) ((ctx->currval >> (ctx->currbits - 8)) & 0xff);
22 ctx->data[ctx->offset++] = tmp;
23 } else {
24 /* If buffer has been exhausted, truncate bitstream */
25 ctx->truncated = 1;
26 }
27
28 ctx->currbits -= 8;
29 }
30}
#define NULL
Definition gmacros.h:924

References duk_bitencoder_ctx::currbits, duk_bitencoder_ctx::currval, duk_bitencoder_ctx::data, DUK_ASSERT, duk_bitencoder_ctx::length, NULL, duk_bitencoder_ctx::offset, and duk_bitencoder_ctx::truncated.

Referenced by duk_be_finish().

◆ duk_be_finish()

DUK_INTERNAL void duk_be_finish ( duk_bitencoder_ctx * ctx)

Definition at line 32 of file duktape-1.5.2/src-separate/duk_util_bitencoder.c.

32 {
33 duk_small_int_t npad;
34
35 DUK_ASSERT(ctx != NULL);
36 DUK_ASSERT(ctx->currbits < 8);
37
38 npad = (duk_small_int_t) (8 - ctx->currbits);
39 if (npad > 0) {
40 duk_be_encode(ctx, 0, npad);
41 }
42 DUK_ASSERT(ctx->currbits == 0);
43}
DUK_INTERNAL void duk_be_encode(duk_bitencoder_ctx *ctx, duk_uint32_t data, duk_small_int_t bits)

References duk_bitencoder_ctx::currbits, DUK_ASSERT, duk_be_encode(), and NULL.