• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlange-42 / ark-serde / 14019558887

23 Mar 2025 01:38PM CUT coverage: 96.023%. Remained the same
14019558887

push

github

web-flow
Profiling and optimizations (#13)

* use slice for component infos
* add profiling projects
* update changelog

3 of 3 new or added lines in 1 file covered. (100.0%)

338 of 352 relevant lines covered (96.02%)

42.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/options.go
1
package arkserde
2

3
import (
4
        "reflect"
5

6
        "github.com/mlange-42/ark/ecs"
7
)
8

9
// Opts is a helper to create Option instances.
10
var Opts = Options{}
11

12
// Option is an option. Modifies o.
13
// Create them using [Opts].
14
type Option func(o *serdeOptions)
15

16
// Options is a helper to create Option instances.
17
// Use it via the instance [Opts].
18
type Options struct{}
19

20
// SkipAllResources skips serialization or de-serialization of all resources.
21
func (o Options) SkipAllResources() Option {
3✔
22
        return func(o *serdeOptions) {
6✔
23
                o.skipAllResources = true
3✔
24
        }
3✔
25
}
26

27
// SkipAllComponents skips serialization or de-serialization of all components.
28
func (o Options) SkipAllComponents() Option {
3✔
29
        return func(o *serdeOptions) {
6✔
30
                o.skipAllComponents = true
3✔
31
        }
3✔
32
}
33

34
// SkipEntities skips serialization or de-serialization of all entities and components.
35
func (o Options) SkipEntities() Option {
3✔
36
        return func(o *serdeOptions) {
6✔
37
                o.skipEntities = true
3✔
38
        }
3✔
39
}
40

41
// SkipComponents skips serialization or de-serialization of certain components.
42
//
43
// When deserializing, the skipped components must still be registered.
44
func (o Options) SkipComponents(comps ...ecs.Comp) Option {
3✔
45
        return func(o *serdeOptions) {
6✔
46
                o.skipComponents = make([]reflect.Type, len(comps))
3✔
47
                for i, c := range comps {
6✔
48
                        o.skipComponents[i] = c.Type()
3✔
49
                }
3✔
50
        }
51
}
52

53
// SkipResources skips serialization or de-serialization of certain resources.
54
//
55
// When deserializing, the skipped resources must still be registered.
56
func (o Options) SkipResources(comps ...ecs.Comp) Option {
3✔
57
        return func(o *serdeOptions) {
6✔
58
                o.skipResources = make([]reflect.Type, len(comps))
3✔
59
                for i, c := range comps {
6✔
60
                        o.skipResources[i] = c.Type()
3✔
61
                }
3✔
62
        }
63
}
64

65
type serdeOptions struct {
66
        skipAllResources  bool
67
        skipAllComponents bool
68
        skipEntities      bool
69

70
        skipComponents []reflect.Type
71
        skipResources  []reflect.Type
72
}
73

74
func newSerdeOptions(opts ...Option) serdeOptions {
40✔
75
        o := serdeOptions{}
40✔
76
        for _, opt := range opts {
55✔
77
                opt(&o)
15✔
78
        }
15✔
79
        return o
40✔
80
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc