Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
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
Container registry
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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
5fa5ca40
Commit
5fa5ca40
authored
11 years ago
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
binary: Factor out mp_binary_set_int().
parent
539681ff
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
py/binary.c
+18
-16
18 additions, 16 deletions
py/binary.c
py/binary.h
+1
-0
1 addition, 0 deletions
py/binary.h
with
19 additions
and
16 deletions
py/binary.c
+
18
−
16
View file @
5fa5ca40
...
@@ -177,6 +177,23 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte **ptr) {
...
@@ -177,6 +177,23 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte **ptr) {
}
}
}
}
void
mp_binary_set_int
(
uint
val_sz
,
bool
big_endian
,
byte
*
p
,
byte
*
val_ptr
)
{
int
in_delta
,
out_delta
;
if
(
big_endian
)
{
in_delta
=
-
1
;
out_delta
=
1
;
val_ptr
+=
val_sz
-
1
;
}
else
{
in_delta
=
out_delta
=
1
;
}
for
(
uint
i
=
val_sz
;
i
>
0
;
i
--
)
{
*
p
=
*
val_ptr
;
p
+=
out_delta
;
val_ptr
+=
in_delta
;
}
}
void
mp_binary_set_val
(
char
struct_type
,
char
val_type
,
mp_obj_t
val_in
,
byte
**
ptr
)
{
void
mp_binary_set_val
(
char
struct_type
,
char
val_type
,
mp_obj_t
val_in
,
byte
**
ptr
)
{
byte
*
p
=
*
ptr
;
byte
*
p
=
*
ptr
;
uint
align
;
uint
align
;
...
@@ -206,22 +223,7 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte **
...
@@ -206,22 +223,7 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte **
val
=
mp_obj_get_int
(
val_in
);
val
=
mp_obj_get_int
(
val_in
);
}
}
int
in_delta
,
out_delta
;
mp_binary_set_int
(
MIN
(
size
,
sizeof
(
val
)),
struct_type
==
'>'
,
p
,
in
);
uint
val_sz
=
MIN
(
size
,
sizeof
(
val
));
if
(
struct_type
==
'>'
)
{
in_delta
=
-
1
;
out_delta
=
1
;
in
+=
val_sz
-
1
;
}
else
{
in_delta
=
out_delta
=
1
;
}
for
(
uint
i
=
val_sz
;
i
>
0
;
i
--
)
{
*
p
=
*
in
;
p
+=
out_delta
;
in
+=
in_delta
;
}
}
}
void
mp_binary_set_val_array
(
char
typecode
,
void
*
p
,
int
index
,
mp_obj_t
val_in
)
{
void
mp_binary_set_val_array
(
char
typecode
,
void
*
p
,
int
index
,
mp_obj_t
val_in
)
{
...
...
This diff is collapsed.
Click to expand it.
py/binary.h
+
1
−
0
View file @
5fa5ca40
...
@@ -35,3 +35,4 @@ void mp_binary_set_val_array_from_int(char typecode, void *p, int index, mp_int_
...
@@ -35,3 +35,4 @@ void mp_binary_set_val_array_from_int(char typecode, void *p, int index, mp_int_
mp_obj_t
mp_binary_get_val
(
char
struct_type
,
char
val_type
,
byte
**
ptr
);
mp_obj_t
mp_binary_get_val
(
char
struct_type
,
char
val_type
,
byte
**
ptr
);
void
mp_binary_set_val
(
char
struct_type
,
char
val_type
,
mp_obj_t
val_in
,
byte
**
ptr
);
void
mp_binary_set_val
(
char
struct_type
,
char
val_type
,
mp_obj_t
val_in
,
byte
**
ptr
);
mp_int_t
mp_binary_get_int
(
uint
size
,
bool
is_signed
,
bool
big_endian
,
byte
*
p
);
mp_int_t
mp_binary_get_int
(
uint
size
,
bool
is_signed
,
bool
big_endian
,
byte
*
p
);
void
mp_binary_set_int
(
uint
val_sz
,
bool
big_endian
,
byte
*
p
,
byte
*
val_ptr
);
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