From 3888d15001e4f6ee8319874184b78c072fca577e Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Thu, 30 Oct 2025 11:55:19 -0700 Subject: Allow all values to be pointers This solves the issue of whether the field was populated or not, at the expense of some horrible memory patterns. But on the plus side it doesn't require any extra API so we might as well allow it. --- ccl_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'ccl_test.go') diff --git a/ccl_test.go b/ccl_test.go index 938af09..ab4833f 100644 --- a/ccl_test.go +++ b/ccl_test.go @@ -11,6 +11,7 @@ import ( func TestUnmarshal(t *testing.T) { t.Parallel() + type byteSliceWrapper []byte type nestedMessage struct { Field int64 `ccl:"field"` } @@ -34,8 +35,11 @@ func TestUnmarshal(t *testing.T) { Repeated []int64 `ccl:"repeated"` RepeatedMessage []*nestedMessage `ccl:"repeated_message"` Bytes []byte `ccl:"bytes"` + BytesWrapper byteSliceWrapper `ccl:"bytes_wrapper"` Time time.Time `ccl:"time"` TimePointer *time.Time `ccl:"time_pointer"` + IntPointer *int `ccl:"int_pointer"` + RepeatedPointer []*int `ccl:"repeated_pointer"` Ignore map[int]int `ccl:"-,"` // unlike JSON this also means ignore unexported int64 @@ -329,6 +333,10 @@ from string'`, desc: "Base64", msg: `bytes:"dGVzdA=="`, want: message{Bytes: []byte("test")}, + }, { + desc: "NotBase64", + msg: `bytes_wrapper: [1, 2, 3]`, + want: message{BytesWrapper: byteSliceWrapper{1, 2, 3}}, }, { desc: "TextUnmarshaler", msg: `time:"2025-10-28T07:41:47Z"`, @@ -337,6 +345,14 @@ from string'`, desc: "TextUnmarshalerPointer", msg: `time_pointer:"2025-10-28T07:41:47Z"`, want: message{TimePointer: &[]time.Time{time.Date(2025, time.October, 28, 7, 41, 47, 0, time.UTC)}[0]}, + }, { + desc: "IntPointer", + msg: `int_pointer: 5`, + want: message{IntPointer: &[]int{5}[0]}, + }, { + desc: "RepeatedPointer", + msg: `repeated_pointer: [1, 2, 3]`, + want: message{RepeatedPointer: []*int{&[]int{1}[0], &[]int{2}[0], &[]int{3}[0]}}, }} { t.Run(tc.desc, func(t *testing.T) { t.Parallel() @@ -454,6 +470,9 @@ func TestUnmarshal_Invalid(t *testing.T) { }, { desc: "Base64", msg: `bytes:"dGVzdAo"`, + }, { + desc: "NotBase64", + msg: `bytes:[1,2,3]`, }, { desc: "BadField", msg: `asdfasdfasdf:"asdf"`, -- cgit v1.3.1