~rogpeppe/mgo/trunk

« back to all changes in this revision

Viewing changes to bson/encode.go

  • Committer: Gustavo Niemeyer
  • Date: 2013-04-11 06:18:48 UTC
  • Revision ID: gustavo@niemeyer.net-20130411061848-6rf0ivho49cb1hgb
Tags: r2013.04.11
Document inlining of maps, and error out if inlined map keys conflict
with struct fields when encoding.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
package bson
29
29
 
30
30
import (
 
31
        "fmt"
31
32
        "math"
32
33
        "net/url"
33
34
        "reflect"
131
132
        }
132
133
        var value reflect.Value
133
134
        if sinfo.InlineMap >= 0 {
134
 
                e.addMap(v.Field(sinfo.InlineMap))
 
135
                m := v.Field(sinfo.InlineMap)
 
136
                if m.Len() > 0 {
 
137
                        for _, k := range m.MapKeys() {
 
138
                                ks := k.String()
 
139
                                if _, found := sinfo.FieldsMap[ks]; found {
 
140
                                        panic(fmt.Sprintf("Can't have key %q in inlined map; conflicts with struct field", ks))
 
141
                                }
 
142
                                e.addElem(ks, m.MapIndex(k), false)
 
143
                        }
 
144
                }
135
145
        }
136
146
        for _, info := range sinfo.FieldsList {
137
147
                if info.Inline == nil {