Index: bxl_decode.c =================================================================== --- bxl_decode.c (revision 30729) +++ bxl_decode.c (revision 30730) @@ -302,6 +302,7 @@ /* pad the last byte */ while(ctx->out_len == 0) append(ctx, 0); + ctx->plain_len++; } ctx->out[ctx->out_len++] = '\r'; ctx->out[ctx->out_len++] = '\n'; @@ -308,7 +309,21 @@ return ctx->out_len; } +int pcb_bxl_encode_len(hdecode_t *ctx) +{ + unsigned long int len = ctx->plain_len-1; + int n; + ctx->bitpos = ctx->out_len = 0; + + for(n = 0; n < 32; n++) { + append(ctx, len & 1); + len >>= 1; + } + return ctx->out_len; +} + + void pcb_bxl_encode_init(hdecode_t *ctx) { pcb_bxl_decode_init(ctx); Index: bxl_decode.h =================================================================== --- bxl_decode.h (revision 30729) +++ bxl_decode.h (revision 30730) @@ -73,6 +73,10 @@ int pcb_bxl_encode_char(hdecode_t *ctx, int inchr); /* Call this at the end of the output stream to flush the last incomplete - output byte */ + output byte. Same return as pcb_bxl_encode_char. */ int pcb_bxl_encode_eof(hdecode_t *ctx); +/* Call this after pcb_bxl_encode_eof() to generate the "length header" that + shall be written at the beginning of the stream. */ +int pcb_bxl_encode_len(hdecode_t *ctx); +