Unverified Commit 989bb0ca authored by Mouse's avatar Mouse Committed by GitHub

Merge pull request #133 from v0-e/dev

parents 75cc7759 d866a059
...@@ -6,21 +6,15 @@ ...@@ -6,21 +6,15 @@
#include <asn_internal.h> #include <asn_internal.h>
#include <BIT_STRING.h> #include <BIT_STRING.h>
static const char *_bit_pattern[16] = {
"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111",
"1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"
};
asn_enc_rval_t asn_enc_rval_t
BIT_STRING_encode_jer(const asn_TYPE_descriptor_t *td, const void *sptr, BIT_STRING_encode_jer(const asn_TYPE_descriptor_t *td, const void *sptr,
int ilevel, enum jer_encoder_flags_e flags, int ilevel, enum jer_encoder_flags_e flags,
asn_app_consume_bytes_f *cb, void *app_key) { asn_app_consume_bytes_f *cb, void *app_key) {
asn_enc_rval_t er = {0, 0, 0}; asn_enc_rval_t er = {0, 0, 0};
char scratch[128]; const char * const h2c = "0123456789ABCDEF";
char scratch[16 * 3 + 4];
char *p = scratch; char *p = scratch;
char *scend = scratch + (sizeof(scratch) - 10);
const BIT_STRING_t *st = (const BIT_STRING_t *)sptr; const BIT_STRING_t *st = (const BIT_STRING_t *)sptr;
int xcan = 0;
uint8_t *buf; uint8_t *buf;
uint8_t *end; uint8_t *end;
...@@ -33,36 +27,32 @@ BIT_STRING_encode_jer(const asn_TYPE_descriptor_t *td, const void *sptr, ...@@ -33,36 +27,32 @@ BIT_STRING_encode_jer(const asn_TYPE_descriptor_t *td, const void *sptr,
end = buf + st->size - 1; /* Last byte is special */ end = buf + st->size - 1; /* Last byte is special */
/* /*
* Binary dump * Hex dump
*/ */
for(; buf < end; buf++) { *p++ = '"';
int v = *buf; for(int i = 0; buf < end; buf++, i++) {
int nline = xcan?0:(((buf - st->buf) % 8) == 0); if(!(i % 16) && (i || st->size > 16)) {
if(p >= scend || nline) { ASN__CALLBACK(scratch, p-scratch);
ASN__CALLBACK(scratch, p - scratch);
p = scratch; p = scratch;
if(nline) ASN__TEXT_INDENT(1, ilevel);
} }
memcpy(p + 0, _bit_pattern[v >> 4], 4); *p++ = h2c[*buf >> 4];
memcpy(p + 4, _bit_pattern[v & 0x0f], 4); *p++ = h2c[*buf & 0x0F];
p += 8;
} }
if(!xcan && ((buf - st->buf) % 8) == 0)
ASN__TEXT_INDENT(1, ilevel);
ASN__CALLBACK(scratch, p - scratch); ASN__CALLBACK(scratch, p - scratch);
p = scratch; p = scratch;
if(buf == end) { if(buf == end) {
int v = *buf;
int ubits = st->bits_unused; int ubits = st->bits_unused;
int i; uint8_t v = *buf & (0xff << ubits);
for(i = 7; i >= ubits; i--) *p++ = h2c[v >> 4];
*p++ = (v & (1 << i)) ? 0x31 : 0x30; *p++ = h2c[v & 0x0F];
ASN__CALLBACK(scratch, p - scratch); ASN__CALLBACK(scratch, p - scratch);
p = scratch;
} }
*p++ = '"';
if(!xcan) ASN__TEXT_INDENT(1, ilevel - 1); ASN__CALLBACK(scratch, p - scratch);
ASN__TEXT_INDENT(1, ilevel - 1);
ASN__ENCODED_OK(er); ASN__ENCODED_OK(er);
cb_failed: cb_failed:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment