(v reflect.Value, rdser *Serializer, cache *ctagsWCache)
| 125 | } |
| 126 | |
| 127 | func (enc *Encoder) encodeStruct(v reflect.Value, rdser *Serializer, cache *ctagsWCache) error { |
| 128 | t := v.Type() |
| 129 | numField := v.NumField() |
| 130 | var entries []ctagsWCacheEntry |
| 131 | if cache != nil { |
| 132 | entries = *cache |
| 133 | } |
| 134 | for field := range numField { |
| 135 | if cache != nil { |
| 136 | // We have not interface fields on top level, so using cache. |
| 137 | if field < len(entries) { |
| 138 | ce := &entries[field] |
| 139 | if ce.ctagName != 0 || ce.isPrivate { |
| 140 | if !ce.isPrivate { |
| 141 | // process field, except private unexported fields |
| 142 | err := enc.encodeValue(v.Field(field), rdser, ce.fieldInfo, &ce.subCache) |
| 143 | if err != nil { |
| 144 | return err |
| 145 | } |
| 146 | } |
| 147 | continue |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | ce := cache.LookupField(field) |
| 152 | if ce.ctagName != 0 || ce.isPrivate { |
| 153 | if !ce.isPrivate { |
| 154 | // process field, except private unexported fields |
| 155 | err := enc.encodeValue(v.Field(field), rdser, ce.fieldInfo, &ce.subCache) |
| 156 | if err != nil { |
| 157 | return err |
| 158 | } |
| 159 | } |
| 160 | continue |
| 161 | } |
| 162 | |
| 163 | // No data in cache: use reflect to get data about field. |
| 164 | vv := v.Field(field) |
| 165 | f := t.Field(field) |
| 166 | name, skip, omitempty := parseStructField(f) |
| 167 | ctagName := 0 |
| 168 | if !skip { |
| 169 | ctagName = enc.name2tag(name) |
| 170 | } |
| 171 | |
| 172 | fi := mkFieldInfo(vv, ctagName, f) |
| 173 | fi.isPrivate = len(f.PkgPath) != 0 || skip |
| 174 | fi.isOmitEmpty = omitempty |
| 175 | |
| 176 | var subCache *ctagsWCache |
| 177 | if !enc.tmUpdated { |
| 178 | ce.fieldInfo = fi |
| 179 | if !fi.isPrivate { |
| 180 | subCache = &ce.subCache |
| 181 | } |
| 182 | } |
| 183 | if !fi.isPrivate { |
| 184 | // process field, except private unexported fields |
no test coverage detected