@@ -32,14 +32,7 @@ fn parse_journal_entry_log2(line: &str) -> Result<JournalEntry, Box<dyn Error +
3232 let short_time = parts_iter. next ( ) . unwrap_or_default ( ) . parse ( ) . unwrap_or ( -1 ) ;
3333 let domain = parts_iter. next ( ) ;
3434 let value_flags = ValueFlags :: from_bits_retain ( parts_iter. next ( ) . unwrap_or_default ( ) . parse ( ) . unwrap_or ( 0 ) ) ;
35- let user_id = parts_iter
36- . next ( )
37- . map_or_else ( || Ok ( RpcValue :: null ( ) ) , |user_id| if user_id. is_empty ( ) {
38- Ok ( RpcValue :: null ( ) )
39- } else {
40- RpcValue :: from_cpon ( user_id)
41- . map_err ( |err| format ! ( "Cannot parse user_id from CPON: `{user_id}` on line: {line}, error: {err}" ) )
42- } ) ?;
35+ let user_id = parts_iter. next ( ) . map_or_else ( String :: new, String :: from) ;
4336
4437 Ok ( JournalEntry {
4538 epoch_msec,
@@ -128,7 +121,7 @@ where
128121 }
129122 value_flags. bits ( ) . to_string ( )
130123 } ,
131- if entry. user_id . is_null ( ) { "" . into ( ) } else { entry . user_id . to_cpon ( ) } ,
124+ entry. user_id . clone ( ) ,
132125 ] . join ( JOURNAL_ENTRIES_SEPARATOR ) + "\n " ;
133126 self . writer . write_all ( line. as_bytes ( ) ) . await ?;
134127 self . writer . flush ( ) . await
@@ -179,8 +172,8 @@ pub fn journal_entry_to_log3_imap(entry: JournalEntry) -> shvproto::IMap {
179172 if entry. access_level != AccessLevel :: Read as _ {
180173 imap. insert ( Log3Key :: AccessLevel as _ , entry. access_level . into ( ) ) ;
181174 }
182- if !entry. user_id . is_null ( ) {
183- imap. insert ( Log3Key :: UserId as _ , entry. user_id ) ;
175+ if !entry. user_id . is_empty ( ) {
176+ imap. insert ( Log3Key :: UserId as _ , entry. user_id . into ( ) ) ;
184177 }
185178 if entry. repeat {
186179 imap. insert ( Log3Key :: Repeat as _ , entry. repeat . into ( ) ) ;
@@ -263,7 +256,7 @@ fn parse_journal_entry_log3(line: impl AsRef<str>) -> Result<JournalEntry, Box<d
263256 . map_or ( AccessLevel :: Read as _ , RpcValue :: as_i32) ;
264257 let user_id = entry
265258 . get ( & ( Log3Key :: UserId as _ ) )
266- . map_or_else ( RpcValue :: null , RpcValue :: clone ) ;
259+ . map_or_else ( String :: new , |rv| rv . as_str ( ) . into ( ) ) ;
267260 let repeat = entry
268261 . get ( & ( Log3Key :: Repeat as _ ) )
269262 . is_some_and ( RpcValue :: as_bool) ;
@@ -409,7 +402,7 @@ fn rpcvalue_to_journal_entry(entry: &RpcValue, paths_dict: &BTreeMap<i32, String
409402 } ;
410403 let value_flags = ValueFlags :: from_bits_retain ( value_flags) ;
411404
412- let user_id = row. next ( ) . map_or_else ( RpcValue :: null , RpcValue :: clone ) ;
405+ let user_id = row. next ( ) . map_or_else ( String :: new , |rv| rv . as_str ( ) . into ( ) ) ;
413406
414407 Ok ( JournalEntry {
415408 epoch_msec : timestamp. epoch_msec ( ) ,
@@ -864,7 +857,7 @@ mod tests {
864857 value : shvproto:: make_map!( "a" => 1 , "b" => 2 ) . into ( ) ,
865858 access_level : AccessLevel :: Read as _ ,
866859 short_time : 123 ,
867- user_id : ( ) . into ( ) ,
860+ user_id : String :: default ( ) ,
868861 repeat : true ,
869862 provisional : true ,
870863 } ,
@@ -876,7 +869,7 @@ mod tests {
876869 value : shvproto:: make_map!( "a" => 1 , "b" => 2 ) . into ( ) ,
877870 access_level : AccessLevel :: Read as _ ,
878871 short_time : -1 ,
879- user_id : shvproto:: make_map!( "userName" => "abc" , "agent" => "xyz" ) . into ( ) ,
872+ user_id : shvproto:: RpcValue :: from ( shvproto :: make_map!( "userName" => "abc" , "agent" => "xyz" ) ) . to_cpon ( ) ,
880873 repeat : false ,
881874 provisional : true ,
882875 } ,
@@ -923,7 +916,7 @@ mod tests {
923916 value : shvproto:: make_map!( "a" => 1 , "b" => 2 ) . into ( ) ,
924917 access_level : AccessLevel :: Read as _ ,
925918 short_time : -1 ,
926- user_id : ( ) . into ( ) ,
919+ user_id : String :: default ( ) ,
927920 repeat : true ,
928921 provisional : true ,
929922 } ,
@@ -935,7 +928,7 @@ mod tests {
935928 value : shvproto:: make_map!( "a" => 1 , "b" => 2 ) . into ( ) ,
936929 access_level : AccessLevel :: Read as _ ,
937930 short_time : -1 ,
938- user_id : shvproto:: make_map!( "userName" => "abc" , "agent" => "xyz" ) . into ( ) ,
931+ user_id : shvproto:: RpcValue :: from ( shvproto :: make_map!( "userName" => "abc" , "agent" => "xyz" ) ) . to_cpon ( ) ,
939932 repeat : false ,
940933 provisional : true ,
941934 } ,
@@ -1048,7 +1041,7 @@ mod tests {
10481041 fn parse_journal_entry_log2_variants ( ) {
10491042 // All fields present
10501043 assert_eq ! ( parse_journal_entry_log2(
1051- "2025-04-28T11:51:14.300Z\t \t system/status\t 2u\t \t chng\t 1" ) . unwrap( ) ,
1044+ "2025-04-28T11:51:14.300Z\t \t system/status\t 2u\t \t chng\t 1\t user " ) . unwrap( ) ,
10521045 JournalEntry {
10531046 epoch_msec: shvproto:: DateTime :: from_iso_str( "2025-04-28T11:51:14.300Z" ) . unwrap( ) . epoch_msec( ) ,
10541047 path: "system/status" . into( ) ,
@@ -1057,7 +1050,7 @@ mod tests {
10571050 value: 2u64 . into( ) ,
10581051 access_level: AccessLevel :: Read as i32 ,
10591052 short_time: -1 ,
1060- user_id: ( ) . into( ) ,
1053+ user_id: "user" . into( ) ,
10611054 repeat: true ,
10621055 provisional: false ,
10631056 }
@@ -1073,7 +1066,7 @@ mod tests {
10731066 value: 2u64 . into( ) ,
10741067 access_level: AccessLevel :: Read as i32 ,
10751068 short_time: -1 ,
1076- user_id: ( ) . into ( ) ,
1069+ user_id: String :: default ( ) ,
10771070 repeat: true ,
10781071 provisional: false ,
10791072 }
0 commit comments