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::{
88} ;
99use core:: cmp:: Ordering ;
1010
11+ #[ cfg( feature = "alloc" ) ]
12+ use crate :: SliceWriter ;
13+
1114/// ASN.1 `ANY`: represents any explicitly tagged ASN.1 value.
1215///
1316/// This is a zero-copy reference type which borrows from the input data.
@@ -193,6 +196,19 @@ mod allocating {
193196 AnyRef :: from ( self ) . decode_as ( )
194197 }
195198
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+
196212 /// Attempt to decode this value an ASN.1 `SEQUENCE`, creating a new
197213 /// nested reader and calling the provided argument with it.
198214 pub fn sequence < ' a , F , T > ( & ' a self , f : F ) -> Result < T >
You can’t perform that action at this time.
0 commit comments