(t reflect.Type, fields []structField)
| 164 | } |
| 165 | |
| 166 | func structSizeFuncOf(t reflect.Type, fields []structField) sizeFunc { |
| 167 | inlined := inlined(t) |
| 168 | var unique, repeated []*structField |
| 169 | |
| 170 | for i := range fields { |
| 171 | f := &fields[i] |
| 172 | if f.repeated() { |
| 173 | repeated = append(repeated, f) |
| 174 | } else { |
| 175 | unique = append(unique, f) |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | return func(p unsafe.Pointer, flags flags) int { |
| 180 | if p == nil { |
| 181 | return 0 |
| 182 | } |
| 183 | |
| 184 | if !inlined { |
| 185 | flags = flags.without(inline | toplevel) |
| 186 | } else { |
| 187 | flags = flags.without(toplevel) |
| 188 | } |
| 189 | n := 0 |
| 190 | |
| 191 | for _, f := range unique { |
| 192 | size := f.codec.size(f.pointer(p), f.makeFlags(flags)) |
| 193 | if size > 0 { |
| 194 | n += int(f.tagsize) + size |
| 195 | if f.embedded() { |
| 196 | n += sizeOfVarint(uint64(size)) |
| 197 | } |
| 198 | flags = flags.without(wantzero) |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | for _, f := range repeated { |
| 203 | size := f.codec.size(f.pointer(p), f.makeFlags(flags)) |
| 204 | if size > 0 { |
| 205 | n += size |
| 206 | flags = flags.without(wantzero) |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | return n |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | func structEncodeFuncOf(t reflect.Type, fields []structField) encodeFunc { |
| 215 | inlined := inlined(t) |
no test coverage detected
searching dependent graphs…