(b *scode.Builder, val *Record)
| 169 | } |
| 170 | |
| 171 | func buildRecord(b *scode.Builder, val *Record) error { |
| 172 | b.BeginContainer() |
| 173 | typ := super.TypeUnder(val.Type).(*super.TypeRecord) |
| 174 | if nopts := typ.Opts; nopts != 0 { |
| 175 | // Set the none bit for each optional field. |
| 176 | // We assume the invariant that None occurs only in |
| 177 | // optional fields and panic otherwise. |
| 178 | nones := make([]byte, (nopts+7)>>3) |
| 179 | off := 0 |
| 180 | for k, v := range val.Fields { |
| 181 | if typ.Fields[k].Opt { |
| 182 | if _, ok := v.(*None); ok { |
| 183 | nones[off>>3] |= 1 << (off & 7) |
| 184 | } |
| 185 | off++ |
| 186 | } else if _, ok := v.(*None); ok { |
| 187 | panic(v) |
| 188 | } |
| 189 | } |
| 190 | b.Append(nones) |
| 191 | } |
| 192 | for _, v := range val.Fields { |
| 193 | if _, ok := v.(*None); ok { |
| 194 | continue |
| 195 | } |
| 196 | if err := buildValue(b, v); err != nil { |
| 197 | return err |
| 198 | } |
| 199 | } |
| 200 | b.EndContainer() |
| 201 | return nil |
| 202 | } |
| 203 | |
| 204 | func buildArray(b *scode.Builder, array *Array) error { |
| 205 | b.BeginContainer() |
no test coverage detected