Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
asn1c
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
asn1c
Commits
4558ad06
Commit
4558ad06
authored
Jul 10, 2017
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add OER encoder helpers
parent
099da6ff
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
15 deletions
+85
-15
skeletons/oer_encoder.c
skeletons/oer_encoder.c
+69
-0
skeletons/oer_encoder.h
skeletons/oer_encoder.h
+16
-15
No files found.
skeletons/oer_encoder.c
0 → 100644
View file @
4558ad06
/*
* Copyright (c) 2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
* Redistribution and modifications are permitted subject to BSD license.
*/
#include <asn_internal.h>
/*
* The OER encoder of any type.
*/
asn_enc_rval_t
oer_encode
(
asn_TYPE_descriptor_t
*
type_descriptor
,
void
*
struct_ptr
,
asn_app_consume_bytes_f
*
consume_bytes
,
void
*
app_key
)
{
ASN_DEBUG
(
"OER encoder invoked for %s"
,
type_descriptor
->
name
);
/*
* Invoke type-specific encoder.
*/
return
type_descriptor
->
oer_encoder
(
type_descriptor
,
0
,
struct_ptr
,
/* Pointer to the destination structure */
consume_bytes
,
app_key
);
}
/*
* Argument type and callback necessary for oer_encode_to_buffer().
*/
typedef
struct
enc_to_buf_arg
{
void
*
buffer
;
size_t
left
;
}
enc_to_buf_arg
;
static
int
encode_to_buffer_cb
(
const
void
*
buffer
,
size_t
size
,
void
*
key
)
{
enc_to_buf_arg
*
arg
=
(
enc_to_buf_arg
*
)
key
;
if
(
arg
->
left
<
size
)
return
-
1
;
/* Data exceeds the available buffer size */
memcpy
(
arg
->
buffer
,
buffer
,
size
);
arg
->
buffer
=
((
char
*
)
arg
->
buffer
)
+
size
;
arg
->
left
-=
size
;
return
0
;
}
/*
* A variant of the oer_encode() which encodes the data into the provided buffer
*/
asn_enc_rval_t
oer_encode_to_buffer
(
struct
asn_TYPE_descriptor_s
*
type_descriptor
,
void
*
struct_ptr
,
/* Structure to be encoded */
void
*
buffer
,
/* Pre-allocated buffer */
size_t
buffer_size
/* Initial buffer size (maximum) */
)
{
enc_to_buf_arg
arg
;
asn_enc_rval_t
ec
;
arg
.
buffer
=
buffer
;
arg
.
left
=
buffer_size
;
ec
=
type_descriptor
->
oer_encoder
(
type_descriptor
,
0
,
struct_ptr
,
/* Pointer to the destination structure */
encode_to_buffer_cb
,
&
arg
);
if
(
ec
.
encoded
!=
-
1
)
{
assert
(
ec
.
encoded
==
(
ssize_t
)(
buffer_size
-
arg
.
left
));
/* Return the encoded contents size */
}
return
ec
;
}
skeletons/oer_encoder.h
View file @
4558ad06
...
...
@@ -34,8 +34,9 @@ asn_enc_rval_t oer_encode_to_buffer(
/*
* Type of the generic OER encoder.
*/
typedef
asn_enc_rval_t
(
oer_type_encoder_f
)(
typedef
asn_enc_rval_t
(
oer_type_encoder_f
)(
struct
asn_TYPE_descriptor_s
*
type_descriptor
,
asn_oer_constraints_t
*
constraints
,
void
*
struct_ptr
,
/* Structure to be encoded */
asn_app_consume_bytes_f
*
consume_bytes_cb
,
/* Callback */
void
*
app_key
/* Arbitrary callback argument */
...
...
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