...
This commit is contained in:
@@ -28,6 +28,7 @@ pub fn encode[T](val T) !string {
|
||||
$if T is $struct {
|
||||
e.encode_struct[T](val)!
|
||||
} $else $if T is $array {
|
||||
//TODO: need to make comma separated list only works if int,u8,u16,i8... or string if string put all elements in \''...\'',...
|
||||
e.add_child_list[T](val, 'TODO')
|
||||
} $else {
|
||||
return error('can only add elements for struct or array of structs. \n${val}')
|
||||
@@ -128,18 +129,30 @@ pub fn (mut e Encoder) encode_struct[T](t T) ! {
|
||||
|
||||
// encode children structs and array of structs
|
||||
$for field in T.fields {
|
||||
val := t.$(field.name)
|
||||
// time is encoded in the above params encoding step so skip and dont treat as recursive struct
|
||||
$if val is time.Time || val is ourtime.OurTime {
|
||||
} $else $if val is $struct {
|
||||
if field.name[0].is_capital() {
|
||||
embedded_params := paramsparser.encode(val, recursive: false)!
|
||||
e.params.params << embedded_params.params
|
||||
} else {
|
||||
e.add(val)!
|
||||
// Check if field has skip attribute
|
||||
mut should_skip := false
|
||||
|
||||
for attr in field.attrs {
|
||||
if attr.contains('skip') {
|
||||
should_skip = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if ! should_skip {
|
||||
val := t.$(field.name)
|
||||
// time is encoded in the above params encoding step so skip and dont treat as recursive struct
|
||||
$if val is time.Time || val is ourtime.OurTime {
|
||||
} $else $if val is $struct {
|
||||
if field.name[0].is_capital() {
|
||||
embedded_params := paramsparser.encode(val, recursive: false)!
|
||||
e.params.params << embedded_params.params
|
||||
} else {
|
||||
e.add(val)!
|
||||
}
|
||||
} $else $if val is $array {
|
||||
e.encode_array(val)!
|
||||
}
|
||||
} $else $if val is $array {
|
||||
e.encode_array(val)!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user