Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
shrapnel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
shrapnel
Commits
44da5adc
Commit
44da5adc
authored
Oct 18, 2014
by
Sam Rushing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
standard encoding for python float (C double) using IEEE 754.
parent
135a7646
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
0 deletions
+17
-0
coro/asn1/python.pyx
coro/asn1/python.pyx
+6
-0
test/test_asn1_python.py
test/test_asn1_python.py
+11
-0
No files found.
coro/asn1/python.pyx
View file @
44da5adc
...
...
@@ -13,6 +13,7 @@
#
from
coro.asn1.ber
cimport
*
import
struct
class
EncodingError
(
Exception
):
pass
...
...
@@ -48,6 +49,9 @@ cpdef encode (object ob):
elif
type
(
ob
)
is
set
:
# Note: we can't use TAG_SET because the decoder returns it as a list
return
_TLV
(
2
|
<
int
>
FLAGS_STRUCTURED
|
<
int
>
FLAGS_CONTEXT
,
[
encode
(
x
)
for
x
in
ob
])
elif
type
(
ob
)
is
float
:
# IEEE 754 binary64
return
_TLV
(
3
|
<
int
>
FLAGS_CONTEXT
,
struct
.
pack
(
'>d'
,
ob
))
else
:
raise
EncodingError
(
ob
)
...
...
@@ -72,6 +76,8 @@ cdef _pydecode_tuple (tuple ob):
return
d
elif
tag
==
2
:
return
set
([
_pydecode
(
k
)
for
k
in
data
])
elif
tag
==
3
:
return
struct
.
unpack
(
'>d'
,
data
)[
0
]
else
:
raise
DecodingError
(
ob
)
else
:
...
...
test/test_asn1_python.py
View file @
44da5adc
...
...
@@ -52,6 +52,17 @@ class Test (unittest.TestCase):
R
(
set
([
0
,
1
,
2
]),
(
set
([
0
,
1
,
2
]),
11
))
R
(
set
([(
0
,
1
),
2
]),
(
set
([(
0
,
1
),
2
]),
13
))
def
test_float
(
self
):
R
=
self
.
round_trip
R
(
3.1415926535
,
(
3.1415926535
,
10
))
R
(
0.0
,
(
0.0
,
10
))
R
(
-
0.0
,
(
-
0.0
,
10
))
import
random
for
i
in
range
(
1000
):
x
=
random
.
randint
(
0
,
1000000
)
R
(
x
/
1000.0
,
(
x
/
1000.0
,
10
))
R
(
-
x
/
1000.0
,
(
-
x
/
1000.0
,
10
))
def
test_none
(
self
):
R
=
self
.
round_trip
R
(
None
,
(
None
,
2
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment