Split ReadBinary into ReadBinary/ReadBinaryPtr.

This commit is contained in:
Jae Kwon
2015-06-26 16:43:41 -07:00
parent 9965dd5de6
commit 6781b21d32
5 changed files with 26 additions and 15 deletions

View File

@ -72,13 +72,14 @@ func TestAnimalInterface(t *testing.T) {
ptr := reflect.New(rte).Interface()
fmt.Printf("ptr: %v", ptr)
// Make a binary byteslice that represents a snake.
snakeBytes := BinaryBytes(Snake([]byte("snake")))
// Make a binary byteslice that represents a *snake.
foo = Snake([]byte("snake"))
snakeBytes := BinaryBytes(foo)
snakeReader := bytes.NewReader(snakeBytes)
// Now you can read it.
n, err := new(int64), new(error)
it := *ReadBinary(ptr, snakeReader, n, err).(*Animal)
it := ReadBinary(foo, snakeReader, n, err).(Animal)
fmt.Println(it, reflect.TypeOf(it))
}
@ -374,7 +375,7 @@ func TestBinary(t *testing.T) {
// Read onto a pointer
n, err = new(int64), new(error)
res = ReadBinary(instancePtr, bytes.NewReader(data), n, err)
res = ReadBinaryPtr(instancePtr, bytes.NewReader(data), n, err)
if *err != nil {
t.Fatalf("Failed to read into instance: %v", *err)
}