Merge branch 'decode2' into decode3

Change-Id: Iee5b4bf0476eb89a85202635ee75d4c1287133cc
diff --git a/services/wspr/internal/app/app.go b/services/wspr/internal/app/app.go
index 9357713..f26d773 100644
--- a/services/wspr/internal/app/app.go
+++ b/services/wspr/internal/app/app.go
@@ -36,7 +36,8 @@
 
 const (
 	// pkgPath is the prefix os errors in this package.
-	pkgPath  = "v.io/x/ref/services/wspr/internal/app"
+	pkgPath = "v.io/x/ref/services/wspr/internal/app"
+
 	typeFlow = 0
 )
 
diff --git a/services/wspr/internal/app/messaging.go b/services/wspr/internal/app/messaging.go
index fe09c00..aa9c05a 100644
--- a/services/wspr/internal/app/messaging.go
+++ b/services/wspr/internal/app/messaging.go
@@ -126,6 +126,7 @@
 	case GranterResponseMessage:
 		go c.HandleGranterResponse(msg.Id, msg.Data)
 	case TypeMessage:
+		// These messages need to be handled in order so they are done in line.
 		c.HandleTypeMessage(msg.Data)
 	default:
 		w.Error(verror.New(errUnknownMessageType, ctx, msg.Type))
diff --git a/services/wspr/internal/lib/binary_util.go b/services/wspr/internal/lib/binary_util.go
index f35aa34..936376f 100644
--- a/services/wspr/internal/lib/binary_util.go
+++ b/services/wspr/internal/lib/binary_util.go
@@ -18,8 +18,13 @@
 	errUintOverflow = verror.Register(pkgPath+".errUintOverflow", verror.NoRetry, "{1:}{2:} wspr: scalar larger than 8 bytes{:_}")
 )
 
+<<<<<<< HEAD
 // The logic of the two functions here are copied from the vom implementations and
 // should be kept in sync.
+=======
+// This code has been copied from the vom package and should be kept up to date
+// with it.
+>>>>>>> decode2
 
 // Unsigned integers are the basis for all other primitive values.  This is a
 // two-state encoding.  If the number is less than 128 (0 through 0x7f), its
diff --git a/services/wspr/internal/lib/hex_vom.go b/services/wspr/internal/lib/hex_vom.go
index 2dcbb82..a7ac6c0 100644
--- a/services/wspr/internal/lib/hex_vom.go
+++ b/services/wspr/internal/lib/hex_vom.go
@@ -8,8 +8,6 @@
 	"bytes"
 	"encoding/hex"
 	"fmt"
-	"io"
-	"sync"
 
 	"v.io/v23/vom"
 )
@@ -50,70 +48,3 @@
 	}
 	return decoder.Decode(v)
 }
-
-// TypeReader implements io.Reader but allows changing the underlying buffer.
-// This is useful for merging discrete messages that are part of the same flow.
-type TypeReader struct {
-	buf      bytes.Buffer
-	mu       sync.Mutex
-	isClosed bool
-	cond     *sync.Cond
-}
-
-func NewTypeReader() *TypeReader {
-	reader := &TypeReader{}
-	reader.cond = sync.NewCond(&reader.mu)
-	return reader
-}
-
-func (r *TypeReader) Add(data string) error {
-	binBytes, err := hex.DecodeString(data)
-	if err != nil {
-		return err
-	}
-	r.mu.Lock()
-	_, err = r.buf.Write(binBytes)
-	r.mu.Unlock()
-	r.cond.Signal()
-	return err
-}
-
-func (r *TypeReader) Read(p []byte) (int, error) {
-	r.mu.Lock()
-	defer r.mu.Unlock()
-	for {
-		if r.buf.Len() > 0 {
-			return r.buf.Read(p)
-		}
-		if r.isClosed {
-			return 0, io.EOF
-		}
-		r.cond.Wait()
-	}
-
-}
-
-func (r *TypeReader) Close() {
-	r.mu.Lock()
-	r.isClosed = true
-	r.mu.Unlock()
-	r.cond.Broadcast()
-}
-
-// TypeWriter implements io.Writer but allows changing the underlying buffer.
-// This is useful for merging discrete messages that are part of the same flow.
-type TypeWriter struct {
-	writer ClientWriter
-}
-
-func NewTypeWriter(w ClientWriter) *TypeWriter {
-	return &TypeWriter{writer: w}
-}
-
-func (w *TypeWriter) Write(p []byte) (int, error) {
-	err := w.writer.Send(ResponseTypeMessage, p)
-	if err != nil {
-		return 0, err
-	}
-	return len(p), nil
-}
diff --git a/services/wspr/internal/lib/type_reader.go b/services/wspr/internal/lib/type_reader.go
new file mode 100644
index 0000000..9b98161
--- /dev/null
+++ b/services/wspr/internal/lib/type_reader.go
@@ -0,0 +1,61 @@
+// Copyright 2015 The Vanadium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package lib
+
+import (
+	"bytes"
+	"encoding/hex"
+	"io"
+	"sync"
+)
+
+// TypeReader implements io.Reader but allows changing the underlying buffer.
+// This is useful for merging discrete messages that are part of the same flow.
+type TypeReader struct {
+	buf      bytes.Buffer
+	mu       sync.Mutex
+	isClosed bool
+	cond     *sync.Cond
+}
+
+func NewTypeReader() *TypeReader {
+	reader := &TypeReader{}
+	reader.cond = sync.NewCond(&reader.mu)
+	return reader
+}
+
+func (r *TypeReader) Add(data string) error {
+	binBytes, err := hex.DecodeString(data)
+	if err != nil {
+		return err
+	}
+	r.mu.Lock()
+	_, err = r.buf.Write(binBytes)
+	r.mu.Unlock()
+	r.cond.Signal()
+	return err
+}
+
+func (r *TypeReader) Read(p []byte) (int, error) {
+	r.mu.Lock()
+	defer r.mu.Unlock()
+	for {
+		if r.buf.Len() > 0 {
+			return r.buf.Read(p)
+		}
+		if r.isClosed {
+			return 0, io.EOF
+		}
+		r.cond.Wait()
+	}
+
+}
+
+func (r *TypeReader) Close() {
+	r.mu.Lock()
+	r.isClosed = true
+	r.mu.Unlock()
+	r.cond.Broadcast()
+}
diff --git a/services/wspr/internal/lib/type_writer.go b/services/wspr/internal/lib/type_writer.go
new file mode 100644
index 0000000..3536db2
--- /dev/null
+++ b/services/wspr/internal/lib/type_writer.go
@@ -0,0 +1,23 @@
+// Copyright 2015 The Vanadium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package lib
+
+// TypeWriter implements io.Writer but allows changing the underlying buffer.
+// This is useful for merging discrete messages that are part of the same flow.
+type TypeWriter struct {
+	writer ClientWriter
+}
+
+func NewTypeWriter(w ClientWriter) *TypeWriter {
+	return &TypeWriter{writer: w}
+}
+
+func (w *TypeWriter) Write(p []byte) (int, error) {
+	err := w.writer.Send(ResponseTypeMessage, p)
+	if err != nil {
+		return 0, err
+	}
+	return len(p), nil
+}