Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
asn1c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
qwebaby3
asn1c
Commits
97f8edc5
Commit
97f8edc5
authored
11 years ago
by
Lev Walkin
Browse files
Options
Downloads
Patches
Plain Diff
simplify xer encoding
parent
1715b32c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
skeletons/INTEGER.c
+10
-27
10 additions, 27 deletions
skeletons/INTEGER.c
skeletons/tests/check-INTEGER.c
+2
-0
2 additions, 0 deletions
skeletons/tests/check-INTEGER.c
with
12 additions
and
27 deletions
skeletons/INTEGER.c
+
10
−
27
View file @
97f8edc5
...
@@ -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
;
...
...
This diff is collapsed.
Click to expand it.
skeletons/tests/check-INTEGER.c
+
2
−
0
View file @
97f8edc5
...
@@ -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
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment