1+
2+ #nullable disable
3+
4+ using System ;
5+ using MessagePack ;
6+ using Serde ;
7+
8+ namespace Benchmarks
9+ {
10+ // the view models come from a real world app called "AllReady"
11+ [ GenerateSerialize , GenerateDeserialize ]
12+ public partial class LoginViewModel
13+ {
14+ public string Email { get ; set ; }
15+ public string Password { get ; set ; }
16+ public bool RememberMe { get ; set ; }
17+ }
18+
19+ [ GenerateSerialize , GenerateDeserialize ]
20+ [ MessagePackObject ]
21+ public partial record Location
22+ {
23+ [ Key ( 0 ) ]
24+ public int Id { get ; set ; }
25+ [ Key ( 1 ) ]
26+ public string Address1 { get ; set ; }
27+ [ Key ( 2 ) ]
28+ public string Address2 { get ; set ; }
29+ [ Key ( 3 ) ]
30+ public string City { get ; set ; }
31+ [ Key ( 4 ) ]
32+ public string State { get ; set ; }
33+ [ Key ( 5 ) ]
34+ public string PostalCode { get ; set ; }
35+ [ Key ( 6 ) ]
36+ public string Name { get ; set ; }
37+ [ Key ( 7 ) ]
38+ public string PhoneNumber { get ; set ; }
39+ [ Key ( 8 ) ]
40+ public string Country { get ; set ; }
41+
42+ public static Location Sample => new Location
43+ {
44+ Id = 1234 ,
45+ Address1 = "The Street Name" ,
46+ Address2 = "20/11" ,
47+ City = "The City" ,
48+ State = "The State" ,
49+ PostalCode = "abc-12" ,
50+ Name = "Nonexisting" ,
51+ PhoneNumber = "+0 11 222 333 44" ,
52+ Country = "The Greatest"
53+ } ;
54+ }
55+
56+ public sealed partial class LocationWrap : IDeserialize < Location > , IDeserializeProvider < Location >
57+ {
58+ public static LocationWrap Instance { get ; } = new ( ) ;
59+ static IDeserialize < Location > IDeserializeProvider < Location > . DeserializeInstance => Instance ;
60+ private LocationWrap ( ) { }
61+
62+ public static ISerdeInfo SerdeInfo { get ; } = Serde . SerdeInfo . MakeCustom (
63+ "Location" ,
64+ typeof ( Location ) . GetCustomAttributesData ( ) ,
65+ [
66+ ( "id" , Int32Proxy . SerdeInfo , typeof ( Location ) . GetProperty ( "Id" ) ! ) ,
67+ ( "address1" , StringProxy . SerdeInfo , typeof ( Location ) . GetProperty ( "Address1" ) ! ) ,
68+ ( "address2" , StringProxy . SerdeInfo , typeof ( Location ) . GetProperty ( "Address2" ) ! ) ,
69+ ( "city" , StringProxy . SerdeInfo , typeof ( Location ) . GetProperty ( "City" ) ! ) ,
70+ ( "state" , StringProxy . SerdeInfo , typeof ( Location ) . GetProperty ( "State" ) ! ) ,
71+ ( "postalCode" , StringProxy . SerdeInfo , typeof ( Location ) . GetProperty ( "PostalCode" ) ! ) ,
72+ ( "name" , StringProxy . SerdeInfo , typeof ( Location ) . GetProperty ( "Name" ) ! ) ,
73+ ( "phoneNumber" , StringProxy . SerdeInfo , typeof ( Location ) . GetProperty ( "PhoneNumber" ) ! ) ,
74+ ( "country" , StringProxy . SerdeInfo , typeof ( Location ) . GetProperty ( "Country" ) ! )
75+ ] ) ;
76+
77+ Benchmarks . Location Serde . IDeserialize < Benchmarks . Location > . Deserialize ( IDeserializer deserializer )
78+ {
79+ int _l_id = default ! ;
80+ string _l_address1 = default ! ;
81+ string _l_address2 = default ! ;
82+ string _l_city = default ! ;
83+ string _l_state = default ! ;
84+ string _l_postalcode = default ! ;
85+ string _l_name = default ! ;
86+ string _l_phonenumber = default ! ;
87+ string _l_country = default ! ;
88+ ushort _r_assignedValid = 0b0 ;
89+
90+ var _l_serdeInfo = SerdeInfo ;
91+ var typeDeserialize = deserializer . ReadType ( _l_serdeInfo ) ;
92+ int index ;
93+ while ( ( index = typeDeserialize . TryReadIndex ( _l_serdeInfo , out _ ) ) != IDeserializeType . EndOfType )
94+ {
95+ switch ( index )
96+ {
97+ case 0 :
98+ _l_id = typeDeserialize . ReadI32 ( index ) ;
99+ _r_assignedValid |= ( ( ushort ) 1 ) << 0 ;
100+ break ;
101+ case 1 :
102+ _l_address1 = typeDeserialize . ReadString ( index ) ;
103+ _r_assignedValid |= ( ( ushort ) 1 ) << 1 ;
104+ break ;
105+ case 2 :
106+ _l_address2 = typeDeserialize . ReadString ( index ) ;
107+ _r_assignedValid |= ( ( ushort ) 1 ) << 2 ;
108+ break ;
109+ case 3 :
110+ _l_city = typeDeserialize . ReadString ( index ) ;
111+ _r_assignedValid |= ( ( ushort ) 1 ) << 3 ;
112+ break ;
113+ case 4 :
114+ _l_state = typeDeserialize . ReadString ( index ) ;
115+ _r_assignedValid |= ( ( ushort ) 1 ) << 4 ;
116+ break ;
117+ case 5 :
118+ _l_postalcode = typeDeserialize . ReadString ( index ) ;
119+ _r_assignedValid |= ( ( ushort ) 1 ) << 5 ;
120+ break ;
121+ case 6 :
122+ _l_name = typeDeserialize . ReadString ( index ) ;
123+ _r_assignedValid |= ( ( ushort ) 1 ) << 6 ;
124+ break ;
125+ case 7 :
126+ _l_phonenumber = typeDeserialize . ReadString ( index ) ;
127+ _r_assignedValid |= ( ( ushort ) 1 ) << 7 ;
128+ break ;
129+ case 8 :
130+ _l_country = typeDeserialize . ReadString ( index ) ;
131+ _r_assignedValid |= ( ( ushort ) 1 ) << 8 ;
132+ break ;
133+ case Serde . IDeserializeType . IndexNotFound :
134+ typeDeserialize . SkipValue ( ) ;
135+ break ;
136+ default :
137+ throw new InvalidOperationException ( "Unexpected index: " + index ) ;
138+ }
139+ }
140+
141+ if ( _r_assignedValid != 0b111111111 )
142+ {
143+ throw Serde . DeserializeException . UnassignedMember ( ) ;
144+ }
145+
146+ var newType = new Benchmarks . Location ( )
147+ {
148+ Id = _l_id ,
149+ Address1 = _l_address1 ,
150+ Address2 = _l_address2 ,
151+ City = _l_city ,
152+ State = _l_state ,
153+ PostalCode = _l_postalcode ,
154+ Name = _l_name ,
155+ PhoneNumber = _l_phonenumber ,
156+ Country = _l_country ,
157+ } ;
158+ return newType ;
159+ }
160+ }
161+ }
0 commit comments