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
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
oai
asn1c
Commits
a105cbc3
Commit
a105cbc3
authored
17 years ago
by
Lev Walkin
Browse files
Options
Downloads
Patches
Plain Diff
32-bit integer decode/encode in per
parent
63b4126c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
asn1c/tests/check-127.-fnative-types.-gen-PER.c
+69
-0
69 additions, 0 deletions
asn1c/tests/check-127.-fnative-types.-gen-PER.c
skeletons/INTEGER.c
+22
-4
22 additions, 4 deletions
skeletons/INTEGER.c
tests/127-per-long-OK.asn1
+19
-0
19 additions, 0 deletions
tests/127-per-long-OK.asn1
with
110 additions
and
4 deletions
asn1c/tests/check-127.-fnative-types.-gen-PER.c
0 → 100644
+
69
−
0
View file @
a105cbc3
#undef NDEBUG
#include
<stdio.h>
#include
<stdlib.h>
#include
<sys/types.h>
#include
<string.h>
#include
<assert.h>
#include
<ctype.h>
#include
<errno.h>
#include
<T.h>
void
verify
(
T_t
*
ti
)
{
asn_enc_rval_t
er
;
asn_dec_rval_t
rv
;
unsigned
char
buf
[
8
];
T_t
*
to
=
0
;
fprintf
(
stderr
,
"IN: { %ld, %ld }
\n
"
,
ti
->
small32range
,
ti
->
full32range
);
er
=
uper_encode_to_buffer
(
&
asn_DEF_T
,
ti
,
buf
,
sizeof
buf
);
assert
(
er
.
encoded
==
64
);
rv
=
uper_decode
(
0
,
&
asn_DEF_T
,
(
void
*
)
&
to
,
buf
,
sizeof
buf
,
0
,
0
);
assert
(
rv
.
code
==
RC_OK
);
fprintf
(
stderr
,
"ENC: %2x%2x%2x%2x %2x%2x%2x%2x
\n
"
,
buf
[
0
],
buf
[
1
],
buf
[
2
],
buf
[
3
],
buf
[
4
],
buf
[
5
],
buf
[
6
],
buf
[
7
]);
fprintf
(
stderr
,
"OUT: { %ld, %ld } vs { %ld, %ld }
\n
"
,
ti
->
small32range
,
ti
->
full32range
,
to
->
small32range
,
to
->
full32range
);
assert
(
ti
->
small32range
==
to
->
small32range
);
assert
(
ti
->
full32range
==
to
->
full32range
);
xer_fprint
(
stderr
,
&
asn_DEF_T
,
ti
);
xer_fprint
(
stderr
,
&
asn_DEF_T
,
to
);
}
int
main
()
{
T_t
ti
;
ti
.
small32range
=
0
;
ti
.
full32range
=
0
;
verify
(
&
ti
);
ti
.
small32range
=
-
1
;
ti
.
full32range
=
-
1
;
verify
(
&
ti
);
ti
.
small32range
=
-
2000000000
;
ti
.
full32range
=
(
-
2147483647L
-
1
);
verify
(
&
ti
);
ti
.
small32range
=
-
1999999999
;
ti
.
full32range
=
(
-
2147483647L
);
verify
(
&
ti
);
ti
.
small32range
=
2000000000
;
ti
.
full32range
=
2147483647
;
verify
(
&
ti
);
ti
.
small32range
=
1999999999
;
ti
.
full32range
=
2147483647
-
1
;
verify
(
&
ti
);
return
0
;
}
This diff is collapsed.
Click to expand it.
skeletons/INTEGER.c
+
22
−
4
View file @
a105cbc3
...
...
@@ -598,8 +598,18 @@ INTEGER_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
/* #10.5.6 */
ASN_DEBUG
(
"Integer with range %d bits"
,
ct
->
range_bits
);
if
(
ct
->
range_bits
>=
0
)
{
long
value
=
per_get_few_bits
(
pd
,
ct
->
range_bits
);
if
(
value
<
0
)
_ASN_DECODE_STARVED
;
long
value
;
if
(
ct
->
range_bits
==
32
)
{
long
lhalf
;
value
=
per_get_few_bits
(
pd
,
16
);
if
(
value
<
0
)
_ASN_DECODE_STARVED
;
lhalf
=
per_get_few_bits
(
pd
,
16
);
if
(
lhalf
<
0
)
_ASN_DECODE_STARVED
;
value
=
(
value
<<
16
)
|
lhalf
;
}
else
{
value
=
per_get_few_bits
(
pd
,
ct
->
range_bits
);
if
(
value
<
0
)
_ASN_DECODE_STARVED
;
}
ASN_DEBUG
(
"Got value %ld + low %ld"
,
value
,
ct
->
lower_bound
);
value
+=
ct
->
lower_bound
;
...
...
@@ -695,9 +705,17 @@ INTEGER_encode_uper(asn_TYPE_descriptor_t *td,
/* #10.5.6 */
ASN_DEBUG
(
"Encoding integer with range %d bits"
,
ct
->
range_bits
);
if
(
per_put_few_bits
(
po
,
value
-
ct
->
lower_bound
,
if
(
ct
->
range_bits
==
32
)
{
/* TODO: extend to >32 bits */
long
v
=
value
-
ct
->
lower_bound
;
if
(
per_put_few_bits
(
po
,
v
>>
1
,
31
)
||
per_put_few_bits
(
po
,
v
,
1
))
_ASN_ENCODE_FAILED
;
}
else
{
if
(
per_put_few_bits
(
po
,
value
-
ct
->
lower_bound
,
ct
->
range_bits
))
_ASN_ENCODE_FAILED
;
_ASN_ENCODE_FAILED
;
}
_ASN_ENCODED_OK
(
er
);
}
...
...
This diff is collapsed.
Click to expand it.
tests/127-per-long-OK.asn1
0 → 100644
+
19
−
0
View file @
a105cbc3
-- OK: Everything is fine
-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1)
-- .spelio.software.asn1c.test (9363.1.5.1)
-- .127
ModulePERLong
{ iso org(3) dod(6) internet (1) private(4) enterprise(1)
spelio(9363) software(1) asn1c(5) test(1) 127 }
DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
T ::= SEQUENCE {
small32range INTEGER (-2000000000..2000000000),
full32range INTEGER (-2147483648..2147483647)
}
END
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