@ -1,4 +1,4 @@
use crate ::{ upb_ExtensionRegistry , upb_MiniTable , Arena , OwnedArenaBox , RawArena , RawMessage } ;
use crate ::{ upb_ExtensionRegistry , upb_MiniTable , Arena , RawArena , RawMessage } ;
use std ::ptr ::NonNull ;
use std ::ptr ::NonNull ;
// LINT.IfChange(encode_status)
// LINT.IfChange(encode_status)
@ -37,12 +37,12 @@ enum DecodeOption {
/// If Err, then EncodeStatus != Ok.
/// If Err, then EncodeStatus != Ok.
///
///
/// SAFETY:
/// # Safety
/// - `msg` must be associated with `mini_table`.
/// - `msg` must be associated with `mini_table`.
pub unsafe fn encode (
pub unsafe fn encode (
msg : RawMessage ,
msg : RawMessage ,
mini_table : * const upb_MiniTable ,
mini_table : * const upb_MiniTable ,
) -> Result < OwnedArenaBox < [ u8 ] > , EncodeStatus > {
) -> Result < Vec < u8 > , EncodeStatus > {
let arena = Arena ::new ( ) ;
let arena = Arena ::new ( ) ;
let mut buf : * mut u8 = std ::ptr ::null_mut ( ) ;
let mut buf : * mut u8 = std ::ptr ::null_mut ( ) ;
let mut len = 0 usize ;
let mut len = 0 usize ;
@ -55,8 +55,7 @@ pub unsafe fn encode(
if status = = EncodeStatus ::Ok {
if status = = EncodeStatus ::Ok {
assert! ( ! buf . is_null ( ) ) ; // EncodeStatus Ok should never return NULL data, even for len=0.
assert! ( ! buf . is_null ( ) ) ; // EncodeStatus Ok should never return NULL data, even for len=0.
// SAFETY: upb guarantees that `buf` is valid to read for `len`.
// SAFETY: upb guarantees that `buf` is valid to read for `len`.
let slice = NonNull ::new_unchecked ( std ::ptr ::slice_from_raw_parts_mut ( buf , len ) ) ;
Ok ( ( * std ::ptr ::slice_from_raw_parts ( buf , len ) ) . to_vec ( ) )
Ok ( OwnedArenaBox ::new ( slice , arena ) )
} else {
} else {
Err ( status )
Err ( status )
}
}
@ -65,7 +64,7 @@ pub unsafe fn encode(
/// Decodes into the provided message (merge semantics). If Err, then
/// Decodes into the provided message (merge semantics). If Err, then
/// DecodeStatus != Ok.
/// DecodeStatus != Ok.
///
///
/// SAFETY:
/// # Safety
/// - `msg` must be mutable.
/// - `msg` must be mutable.
/// - `msg` must be associated with `mini_table`.
/// - `msg` must be associated with `mini_table`.
pub unsafe fn decode (
pub unsafe fn decode (