MCPcopy Create free account
hub / github.com/ZeppelinMC/Zeppelin / encodePropsStruct

Function encodePropsStruct

properties/encode.go:22–56  ·  view source on GitHub ↗
(dst io.Writer, v reflect.Value)

Source from the content-addressed store, hash-verified

20}
21
22func encodePropsStruct(dst io.Writer, v reflect.Value) error {
23 vt := v.Type()
24 for i := 0; i < v.NumField(); i++ {
25 tf := vt.Field(i)
26 vf := v.Field(i)
27 name, ok, omitempty := name(tf)
28 if !ok {
29 continue
30 }
31 if omitempty && vf.IsZero() {
32 continue
33 }
34
35 if i != 0 {
36 if err := writeString(dst, "\n"); err != nil {
37 return err
38 }
39 }
40
41 if err := writeString(dst, name+"="); err != nil {
42 return err
43 }
44
45 switch vf.Kind() {
46 case reflect.String, reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
47 if err := writeString(dst, fmt.Sprint(vf.Interface())); err != nil {
48 return err
49 }
50 default:
51 return fmt.Errorf("unsupported kind %s for encode struct", vf.Kind())
52 }
53 }
54
55 return nil
56}
57
58func name(tf reflect.StructField) (n string, ok bool, omitempty bool) {
59 if !tf.IsExported() {

Callers 1

MarshalFunction · 0.85

Calls 3

writeStringFunction · 0.85
nameFunction · 0.70
TypeMethod · 0.45

Tested by

no test coverage detected