Skip to content
Snippets Groups Projects
Commit 97f8edc5 authored by Lev Walkin's avatar Lev Walkin
Browse files

simplify xer encoding

parent 1715b32c
No related branches found
No related tags found
No related merge requests found
...@@ -111,47 +111,30 @@ INTEGER__dump(asn_TYPE_descriptor_t *td, const INTEGER_t *st, asn_app_consume_by ...@@ -111,47 +111,30 @@ INTEGER__dump(asn_TYPE_descriptor_t *td, const INTEGER_t *st, asn_app_consume_by
char scratch[32]; /* Enough for 64-bit integer */ char scratch[32]; /* Enough for 64-bit integer */
uint8_t *buf = st->buf; uint8_t *buf = st->buf;
uint8_t *buf_end = st->buf + st->size; uint8_t *buf_end = st->buf + st->size;
signed long accum; signed long value;
ssize_t wrote = 0; ssize_t wrote = 0;
char *p; char *p;
int ret; int ret;
/* if(specs && specs->field_unsigned)
* Advance buf pointer until the start of the value's body. ret = asn_INTEGER2ulong(st, (unsigned long *)&value);
* This will make us able to process large integers using simple case, else
* when the actual value is small ret = asn_INTEGER2long(st, &value);
* (0x0000000000abcdef would yield a fine 0x00abcdef)
*/
/* Skip the insignificant leading bytes */
for(; buf < buf_end-1; buf++) {
switch(*buf) {
case 0x00: if((buf[1] & 0x80) == 0) continue; break;
case 0xff: if((buf[1] & 0x80) != 0) continue; break;
}
break;
}
/* Simple case: the integer size is small */ /* Simple case: the integer size is small */
if((size_t)(buf_end - buf) <= sizeof(accum)) { if(ret == 0) {
const asn_INTEGER_enum_map_t *el; const asn_INTEGER_enum_map_t *el;
size_t scrsize; size_t scrsize;
char *scr; char *scr;
if(buf == buf_end) { el = (value >= 0 || !specs || !specs->field_unsigned)
accum = 0; ? INTEGER_map_value2enum(specs, value) : 0;
} else {
accum = (*buf & 0x80) ? -1 : 0;
for(; buf < buf_end; buf++)
accum = (accum << 8) | *buf;
}
el = INTEGER_map_value2enum(specs, accum);
if(el) { if(el) {
scrsize = el->enum_len + 32; scrsize = el->enum_len + 32;
scr = (char *)alloca(scrsize); scr = (char *)alloca(scrsize);
if(plainOrXER == 0) if(plainOrXER == 0)
ret = snprintf(scr, scrsize, ret = snprintf(scr, scrsize,
"%ld (%s)", accum, el->enum_name); "%ld (%s)", value, el->enum_name);
else else
ret = snprintf(scr, scrsize, ret = snprintf(scr, scrsize,
"<%s/>", el->enum_name); "<%s/>", el->enum_name);
...@@ -165,7 +148,7 @@ INTEGER__dump(asn_TYPE_descriptor_t *td, const INTEGER_t *st, asn_app_consume_by ...@@ -165,7 +148,7 @@ INTEGER__dump(asn_TYPE_descriptor_t *td, const INTEGER_t *st, asn_app_consume_by
scr = scratch; scr = scratch;
ret = snprintf(scr, scrsize, ret = snprintf(scr, scrsize,
(specs && specs->field_unsigned) (specs && specs->field_unsigned)
?"%lu":"%ld", accum); ?"%lu":"%ld", value);
} }
assert(ret > 0 && (size_t)ret < scrsize); assert(ret > 0 && (size_t)ret < scrsize);
return (cb(scr, ret, app_key) < 0) ? -1 : ret; return (cb(scr, ret, app_key) < 0) ? -1 : ret;
......
...@@ -121,6 +121,8 @@ check_unsigned(uint8_t *buf, int size, unsigned long check_long, int check_ret) ...@@ -121,6 +121,8 @@ check_unsigned(uint8_t *buf, int size, unsigned long check_long, int check_ret)
assert(rlong == rlong2); assert(rlong == rlong2);
} }
return;
shared_scratch_start = scratch; shared_scratch_start = scratch;
ret = INTEGER_print(&asn_DEF_INTEGER, &val, 0, _print2buf, scratch); ret = INTEGER_print(&asn_DEF_INTEGER, &val, 0, _print2buf, scratch);
assert(shared_scratch_start < scratch + sizeof(scratch)); assert(shared_scratch_start < scratch + sizeof(scratch));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment