Merge pull request #145 from unistack-org/codec_fix
codec: add []byte support to noop codec
This commit was merged in pull request #145.
	This commit is contained in:
		| @@ -106,6 +106,10 @@ func (c *noopCodec) Unmarshal(d []byte, v interface{}, opts ...Option) error { | |||||||
| 	case *string: | 	case *string: | ||||||
| 		*ve = string(d) | 		*ve = string(d) | ||||||
| 		return nil | 		return nil | ||||||
|  | 	case []byte: | ||||||
|  | 		ve = make([]byte, len(d)) | ||||||
|  | 		copy(ve, d) | ||||||
|  | 		return nil | ||||||
| 	case *[]byte: | 	case *[]byte: | ||||||
| 		*ve = d | 		*ve = d | ||||||
| 		return nil | 		return nil | ||||||
|   | |||||||
| @@ -5,7 +5,7 @@ import ( | |||||||
| 	"testing" | 	"testing" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func TestNoopBytes(t *testing.T) { | func TestNoopBytesPtr(t *testing.T) { | ||||||
| 	req := []byte("test req") | 	req := []byte("test req") | ||||||
| 	rsp := make([]byte, len(req)) | 	rsp := make([]byte, len(req)) | ||||||
|  |  | ||||||
| @@ -19,6 +19,20 @@ func TestNoopBytes(t *testing.T) { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func TestNoopBytes(t *testing.T) { | ||||||
|  | 	req := []byte("test req") | ||||||
|  | 	var rsp []byte | ||||||
|  |  | ||||||
|  | 	nc := NewCodec() | ||||||
|  | 	if err := nc.Unmarshal(req, &rsp); err != nil { | ||||||
|  | 		t.Fatal(err) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if !bytes.Equal(req, rsp) { | ||||||
|  | 		t.Fatalf("req not eq rsp: %s != %s", req, rsp) | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
| func TestNoopString(t *testing.T) { | func TestNoopString(t *testing.T) { | ||||||
| 	req := []byte("test req") | 	req := []byte("test req") | ||||||
| 	var rsp string | 	var rsp string | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user