File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,9 @@ use crate::{
8
8
} ;
9
9
use core:: cmp:: Ordering ;
10
10
11
+ #[ cfg( feature = "alloc" ) ]
12
+ use crate :: SliceWriter ;
13
+
11
14
/// ASN.1 `ANY`: represents any explicitly tagged ASN.1 value.
12
15
///
13
16
/// This is a zero-copy reference type which borrows from the input data.
@@ -193,6 +196,19 @@ mod allocating {
193
196
AnyRef :: from ( self ) . decode_as ( )
194
197
}
195
198
199
+ /// Encode the provided type as an [`Any`] value.
200
+ pub fn encode_from < T > ( msg : & T ) -> Result < Self >
201
+ where
202
+ T : Tagged + EncodeValue ,
203
+ {
204
+ let encoded_len = usize:: try_from ( msg. value_len ( ) ?) ?;
205
+ let mut buf = vec ! [ 0u8 ; encoded_len] ;
206
+ let mut writer = SliceWriter :: new ( & mut buf) ;
207
+ msg. encode_value ( & mut writer) ?;
208
+ writer. finish ( ) ?;
209
+ Any :: new ( msg. tag ( ) , buf)
210
+ }
211
+
196
212
/// Attempt to decode this value an ASN.1 `SEQUENCE`, creating a new
197
213
/// nested reader and calling the provided argument with it.
198
214
pub fn sequence < ' a , F , T > ( & ' a self , f : F ) -> Result < T >
You can’t perform that action at this time.
0 commit comments