mirror of
https://github.com/Icinga/icingadb.git
synced 2026-05-28 04:35:54 -04:00
PackAny(): support types.Binary
This commit is contained in:
parent
bb850ddb5d
commit
ab43673593
2 changed files with 6 additions and 1 deletions
|
|
@ -17,6 +17,8 @@ func PackAny(in interface{}, out io.Writer) error {
|
|||
return packValue(reflect.ValueOf(in), out)
|
||||
}
|
||||
|
||||
var tBytes = reflect.TypeOf([]uint8(nil))
|
||||
|
||||
// packValue does the actual job of packAny and just exists for recursion w/o unneccessary reflect.ValueOf calls.
|
||||
func packValue(in reflect.Value, out io.Writer) error {
|
||||
switch kind := in.Kind(); kind {
|
||||
|
|
@ -50,7 +52,8 @@ func packValue(in reflect.Value, out io.Writer) error {
|
|||
}
|
||||
|
||||
// Pack []byte as string, not array of numbers.
|
||||
return packString(in.Interface().([]uint8), out)
|
||||
return packString(in.Convert(tBytes). // Support types.Binary
|
||||
Interface().([]uint8), out)
|
||||
}
|
||||
|
||||
if _, err := out.Write([]byte{5}); err != nil {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package objectpacker
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/icinga/icingadb/pkg/types"
|
||||
"io"
|
||||
"testing"
|
||||
"unsafe"
|
||||
|
|
@ -129,6 +130,7 @@ func TestPackAny(t *testing.T) {
|
|||
|
||||
assertPackAny(t, binary, append([]byte{4, 0, 0, 0, 0, 0, 0, 1, 0}, binary[:]...))
|
||||
assertPackAny(t, binary[:], append([]byte{4, 0, 0, 0, 0, 0, 0, 1, 0}, binary[:]...))
|
||||
assertPackAny(t, types.Binary(binary[:]), append([]byte{4, 0, 0, 0, 0, 0, 0, 1, 0}, binary[:]...))
|
||||
}
|
||||
|
||||
assertPackAnyPanic(t, complex64(0+0i), 0)
|
||||
|
|
|
|||
Loading…
Reference in a new issue