Permalink
Browse files

provide a hash method for replies

  • Loading branch information...
1 parent bee8559 commit b6cd1de3ea1bee8feb3abf74617b433cf2afba4f Simon Zimmermann committed May 4, 2012
Showing with 26 additions and 0 deletions.
  1. +26 −0 reply.go
View
@@ -36,6 +36,14 @@ func (e Elem) Float64() float64 {
return v
}
+func (r *Reply) Len() int {
+ if r.Elems == nil {
+ return 0
+ }
+
+ return len(r.Elems)
+}
+
func (r *Reply) BytesArray() [][]byte {
buf := make([][]byte, len(r.Elems))
@@ -83,6 +91,24 @@ func (r *Reply) StringMap() map[string]string {
return buf
}
+func (r *Reply) Hash() map[string]Elem {
+ l := r.Len()
+ h := make(map[string]Elem, l/2)
+
+ if l%2 == 1 {
+ return h
+ }
+
+ var key string
+
+ for i := 0; i < l; i += 2 {
+ key = r.Elems[i].Elem.String()
+ h[key] = r.Elems[i + 1].Elem
+ }
+
+ return h
+}
+
func (r *Reply) Message() *Message {
if len(r.Elems) < 3 {
return nil

0 comments on commit b6cd1de

Please sign in to comment.