Skip to content

Commit

Permalink
Simplify logic.
Browse files Browse the repository at this point in the history
Refs #586
  • Loading branch information
echlebek committed Nov 22, 2017
1 parent 5640e85 commit d42b845
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions types/dynamic/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,25 +203,21 @@ func ExtractExtendedAttributes(v interface{}, msg []byte) ([]byte, error) {
if err := jsoniter.Unmarshal(msg, &anys); err != nil {
return nil, err
}
objectStarted := false
stream.WriteObjectStart()
j := 0
for _, any := range sortAnys(anys) {
_, ok := fields[any.Name]
if ok {
// Not a extended attribute
continue
}
if !objectStarted {
objectStarted = true
stream.WriteObjectStart()
} else {
if j > 0 {
stream.WriteMore()
}
j++
stream.WriteObjectField(any.Name)
any.WriteTo(stream)
}
if !objectStarted {
stream.WriteObjectStart()
}
stream.WriteObjectEnd()
return stream.Buffer(), nil
}
Expand Down Expand Up @@ -263,11 +259,8 @@ func encodeStructFields(v interface{}, s *jsoniter.Stream) error {
sort.Slice(fields, func(i, j int) bool {
return fields[i].JSONName < fields[j].JSONName
})
objectStarted := false
for _, field := range fields {
if !objectStarted {
objectStarted = true
} else {
for i, field := range fields {
if i > 0 {
s.WriteMore()
}
s.WriteObjectField(field.JSONName)
Expand Down

0 comments on commit d42b845

Please sign in to comment.