@@ -19,6 +19,7 @@ pub mut:
1919
2020// encode_binary encode a T type data into u8 array.
2121// for encoding struct, you can use `@[serialize: '-']` to skip field.
22+ // Note: `shared` fields in struct will be skipped.
2223pub fn encode_binary [T](obj T, config EncodeConfig) ! []u8 {
2324 mut s := EncodeState{
2425 b: []u8 {cap: config.buffer_len}
@@ -56,17 +57,20 @@ fn encode_struct[T](mut s EncodeState, obj T) ! {
5657 }
5758 }
5859 if ! is_skip {
59- value := obj.$(field.name)
60- $if field.typ is $array {
61- encode_array (mut s, value)!
62- } $else $if field.typ is $string {
63- encode_string (mut s, value)!
64- } $else $if field.typ is $struct {
65- encode_struct (mut s, value)!
66- } $else $if field.typ is $map {
67- encode_map (mut s, value)!
68- } $else {
69- encode_primitive (mut s, value)!
60+ // TODO: support shared field in struct, currently skip.
61+ $if field.typ ! is $shared {
62+ value := obj.$(field.name)
63+ $if field.typ is $array {
64+ encode_array (mut s, value)!
65+ } $else $if field.typ is $string {
66+ encode_string (mut s, value)!
67+ } $else $if field.typ is $struct {
68+ encode_struct (mut s, value)!
69+ } $else $if field.typ is $map {
70+ encode_map (mut s, value)!
71+ } $else {
72+ encode_primitive (mut s, value)!
73+ }
7074 }
7175 }
7276 }
@@ -201,6 +205,7 @@ pub mut:
201205
202206// decode_binary decode a u8 array into T type data.
203207// for decoding struct, you can use `@[serialize: '-']` to skip field.
208+ // Note: `shared` fields in struct will be skipped.
204209pub fn decode_binary [T](b []u8 , config DecodeConfig) ! T {
205210 mut s := DecodeState{
206211 b: b
@@ -239,16 +244,19 @@ fn decode_struct[T](mut s DecodeState, _ T) !T {
239244 }
240245 }
241246 if ! is_skip {
242- $if field.typ is $array {
243- obj.$(field.name) = decode_array (mut s, obj.$(field.name))!
244- } $else $if field.typ is $string {
245- obj.$(field.name) = decode_string (mut s)!
246- } $else $if field.typ is $struct {
247- obj.$(field.name) = decode_struct (mut s, obj.$(field.name))!
248- } $else $if field.typ is $map {
249- obj.$(field.name) = decode_map (mut s, obj.$(field.name))!
250- } $else {
251- obj.$(field.name) = decode_primitive (mut s, obj.$(field.name))!
247+ // TODO: support shared field in struct, currently skip.
248+ $if field.typ ! is $shared {
249+ $if field.typ is $array {
250+ obj.$(field.name) = decode_array (mut s, obj.$(field.name))!
251+ } $else $if field.typ is $string {
252+ obj.$(field.name) = decode_string (mut s)!
253+ } $else $if field.typ is $struct {
254+ obj.$(field.name) = decode_struct (mut s, obj.$(field.name))!
255+ } $else $if field.typ is $map {
256+ obj.$(field.name) = decode_map (mut s, obj.$(field.name))!
257+ } $else {
258+ obj.$(field.name) = decode_primitive (mut s, obj.$(field.name))!
259+ }
252260 }
253261 }
254262 }
0 commit comments