@@ -10,6 +10,7 @@ public class TypeValue
1010 public string RustType { get ; }
1111 public TypeValue InnerType { get ; }
1212 public TypeValue [ ] MultiTypes { get ; }
13+ public int ? Length { get ; }
1314
1415 private readonly int ? _sizeInBytes ;
1516 private readonly bool ? _withSign ;
@@ -31,10 +32,11 @@ public TypeValue(string binaryType, string rustType, FieldDefinition[] fieldDefi
3132 _fieldDefinitions = fieldDefinitions ;
3233 }
3334
34- public TypeValue ( string binaryType , TypeValue innerType = null )
35+ public TypeValue ( string binaryType , TypeValue innerType = null , int ? length = null )
3536 {
3637 BinaryType = binaryType ;
3738 InnerType = innerType ;
39+ Length = length ;
3840 }
3941
4042 public TypeValue ( string binaryType , TypeValue [ ] multiTypes )
@@ -83,6 +85,39 @@ public static class BinaryTypes
8385 public const string Enum = nameof ( Enum ) ;
8486 }
8587
88+ public static class LearnedTypes
89+ {
90+ public const string Option = "Option" ;
91+ public const string List = "List" ;
92+ public const string VarArgs = "VarArgs" ;
93+ public const string MultiResultVec = "MultiResultVec" ;
94+ public const string Variadic = "variadic" ;
95+ public const string OptionalArg = "OptionalArg" ;
96+ public const string Optional = "optional" ;
97+ public const string OptionalResult = "OptionalResult" ;
98+ public const string Multi = "multi" ;
99+ public const string MultiArg = "MultiArg" ;
100+ public const string MultiResult = "MultiResult" ;
101+ public const string Tuple = "tuple" ;
102+ public const string Tuple2 = "tuple2" ;
103+ public const string Tuple3 = "tuple3" ;
104+ public const string Tuple4 = "tuple4" ;
105+ public const string Tuple5 = "tuple5" ;
106+ public const string Tuple6 = "tuple6" ;
107+ public const string Tuple7 = "tuple7" ;
108+ public const string Tuple8 = "tuple8" ;
109+ public const string Array = "Array" ;
110+ public const string Array2 = "array2" ;
111+ public const string Array8 = "array8" ;
112+ public const string Array16 = "array16" ;
113+ public const string Array20 = "array20" ;
114+ public const string Array32 = "array32" ;
115+ public const string Array46 = "array46" ;
116+ public const string Array64 = "array64" ;
117+ public const string Array128 = "array128" ;
118+ public const string Array256 = "array256" ;
119+ }
120+
86121 public static class RustTypes
87122 {
88123 public const string U8 = "u8" ;
@@ -136,13 +171,72 @@ public static class RustTypes
136171 public static TypeValue TupleValue ( TypeValue [ ] tupleTypes ) => new TypeValue ( BinaryTypes . Tuple , tupleTypes ) ;
137172 public static TypeValue VariadicValue ( TypeValue innerType ) => new TypeValue ( BinaryTypes . Variadic , innerType ) ;
138173 public static TypeValue ListValue ( TypeValue innerType ) => new TypeValue ( BinaryTypes . List , innerType ) ;
139- public static TypeValue ArrayValue ( TypeValue innerType ) => new TypeValue ( BinaryTypes . Array , innerType ) ;
140-
174+ public static TypeValue ArrayValue ( TypeValue innerType , int length ) => new TypeValue ( BinaryTypes . Array , innerType , length ) ;
175+
141176 public static TypeValue StructValue ( string name , FieldDefinition [ ] fieldDefinitions ) =>
142177 new TypeValue ( BinaryTypes . Struct , name , fieldDefinitions ) ;
143178 public static TypeValue EnumValue ( string name , FieldDefinition [ ] fieldDefinitions ) =>
144179 new TypeValue ( BinaryTypes . Enum , name , fieldDefinitions ) ;
145180
181+ public static TypeValue FromLearnedType ( string learnedType , TypeValue [ ] types )
182+ {
183+ switch ( learnedType )
184+ {
185+ case LearnedTypes . Option :
186+ return OptionValue ( types [ 0 ] ) ;
187+
188+ case LearnedTypes . List :
189+ return ListValue ( types [ 0 ] ) ;
190+
191+ case LearnedTypes . VarArgs :
192+ case LearnedTypes . MultiResultVec :
193+ case LearnedTypes . Variadic :
194+ return VariadicValue ( types [ 0 ] ) ;
195+
196+ case LearnedTypes . OptionalArg :
197+ case LearnedTypes . Optional :
198+ case LearnedTypes . OptionalResult :
199+ return OptionalValue ( types [ 0 ] ) ;
200+
201+ case LearnedTypes . Multi :
202+ case LearnedTypes . MultiArg :
203+ case LearnedTypes . MultiResult :
204+ return MultiValue ( types ) ;
205+
206+ case LearnedTypes . Tuple :
207+ case LearnedTypes . Tuple2 :
208+ case LearnedTypes . Tuple3 :
209+ case LearnedTypes . Tuple4 :
210+ case LearnedTypes . Tuple5 :
211+ case LearnedTypes . Tuple6 :
212+ case LearnedTypes . Tuple7 :
213+ case LearnedTypes . Tuple8 :
214+ return TupleValue ( types ) ;
215+
216+ case LearnedTypes . Array2 :
217+ return ArrayValue ( types [ 0 ] , 2 ) ;
218+ case LearnedTypes . Array8 :
219+ return ArrayValue ( types [ 0 ] , 8 ) ;
220+ case LearnedTypes . Array16 :
221+ return ArrayValue ( types [ 0 ] , 16 ) ;
222+ case LearnedTypes . Array20 :
223+ return ArrayValue ( types [ 0 ] , 20 ) ;
224+ case LearnedTypes . Array32 :
225+ return ArrayValue ( types [ 0 ] , 32 ) ;
226+ case LearnedTypes . Array46 :
227+ return ArrayValue ( types [ 0 ] , 46 ) ;
228+ case LearnedTypes . Array64 :
229+ return ArrayValue ( types [ 0 ] , 64 ) ;
230+ case LearnedTypes . Array128 :
231+ return ArrayValue ( types [ 0 ] , 128 ) ;
232+ case LearnedTypes . Array256 :
233+ return ArrayValue ( types [ 0 ] , 256 ) ;
234+
235+ default :
236+ return null ;
237+ }
238+ }
239+
146240 public static TypeValue FromRustType ( string rustType )
147241 {
148242 switch ( rustType )
@@ -169,10 +263,10 @@ public static TypeValue FromRustType(string rustType)
169263 case RustTypes . Bigint :
170264 return BigIntTypeValue ;
171265
172- case RustTypes . Bytes :
173- return BytesValue ;
174266 case RustTypes . Bool :
175267 return BooleanValue ;
268+ case RustTypes . Bytes :
269+ return BytesValue ;
176270 case RustTypes . Address :
177271 return AddressValue ;
178272 case RustTypes . TokenIdentifier :
0 commit comments