-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
268 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package parco | ||
|
||
import "io" | ||
|
||
type ( | ||
BasicArrayField[T, U any] struct { | ||
id string | ||
size int | ||
inner ArrayType[U] | ||
setter Setter[T, SliceView[U]] | ||
getter Getter[T, SliceView[U]] | ||
} | ||
) | ||
|
||
func (s BasicArrayField[T, U]) ID() string { | ||
return s.id | ||
} | ||
|
||
func (s BasicArrayField[T, U]) Parse(item *T, r io.Reader) error { | ||
values, err := s.inner.Parse(r) | ||
if err != nil { | ||
return err | ||
} | ||
s.setter(item, values.Unwrap()) | ||
return nil | ||
} | ||
|
||
func (s BasicArrayField[T, U]) Compile(item *T, w io.Writer) error { | ||
value := s.getter(item) | ||
return s.inner.Compile(value, w) | ||
} | ||
|
||
func ArrayField[T, U any]( | ||
length int, | ||
inner Type[U], | ||
setter Setter[T, SliceView[U]], | ||
getter Getter[T, SliceView[U]], | ||
) Field[T, U] { | ||
return BasicArrayField[T, U]{ | ||
inner: Array[U](length, inner), | ||
setter: setter, | ||
getter: getter, | ||
} | ||
} | ||
|
||
func ArrayFieldGetter[T any, U any]( | ||
length int, | ||
inner Type[U], | ||
getter Getter[T, SliceView[U]], | ||
) Field[T, U] { | ||
return ArrayField[T, U]( | ||
length, | ||
inner, | ||
nil, | ||
getter, | ||
) | ||
} | ||
|
||
func ArrayFieldSetter[T, U any]( | ||
length int, | ||
inner Type[U], | ||
setter Setter[T, SliceView[U]], | ||
) Field[T, U] { | ||
return ArrayField[T, U]( | ||
length, | ||
inner, | ||
setter, | ||
nil, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.