From ce350a035880f13ab50c172db19dad15850e7a10 Mon Sep 17 00:00:00 2001 From: Thomas Pelletier Date: Wed, 27 Sep 2023 15:31:53 -0700 Subject: [PATCH] More renames --- types/codec.go | 2 +- types/serde_test.go | 10 +++++----- types/typemap.go | 28 ++++++++++++++-------------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/types/codec.go b/types/codec.go index 55c4d25..6537354 100644 --- a/types/codec.go +++ b/types/codec.go @@ -6,7 +6,7 @@ import ( ) func init() { - RegisterSerde[time.Time](serializeTime, deserializeTime) + Register[time.Time](serializeTime, deserializeTime) } func serializeTime(s *Serializer, x *time.Time) error { diff --git a/types/serde_test.go b/types/serde_test.go index b6400bc..4e08de4 100644 --- a/types/serde_test.go +++ b/types/serde_test.go @@ -203,7 +203,7 @@ func TestReflectCustom(t *testing.T) { } testReflect(t, "int wrapper", func(t *testing.T) { - RegisterSerde[int](ser, des) + Register[int](ser, des) x := 42 p := &x @@ -226,7 +226,7 @@ func TestReflectCustom(t *testing.T) { y Y } - RegisterSerde[int](ser, des) + Register[int](ser, des) x := X{ foo: "test", @@ -251,7 +251,7 @@ func TestReflectCustom(t *testing.T) { y *Y } - RegisterSerde[int](ser, des) + Register[int](ser, des) x := &X{y: &Y{}} x.y.foo = "test" @@ -266,7 +266,7 @@ func TestReflectCustom(t *testing.T) { }) testReflect(t, "custom type in slice", func(t *testing.T) { - RegisterSerde[int](ser, des) + Register[int](ser, des) x := []int{1, 2, 3, 42, 5, 6} assertRoundTrip(t, x) b := Serialize(x) @@ -289,7 +289,7 @@ func TestReflectCustom(t *testing.T) { return nil } - RegisterSerde[http.Client](ser, des) + Register[http.Client](ser, des) x := http.Client{ CheckRedirect: func(req *http.Request, via []*http.Request) error { diff --git a/types/typemap.go b/types/typemap.go index 43c2867..f5e76e8 100644 --- a/types/typemap.go +++ b/types/typemap.go @@ -9,17 +9,17 @@ import ( // Global type register. var types *typemap = newTypemap() -// SerializerFn is the signature of custom serializer functions. Use the +// SerializerFunc is the signature of custom serializer functions. Use the // [Serialize] function to drive the [Serializer]. Returning an error results in // the program panicking. -type SerializerFn[T any] func(*Serializer, *T) error +type SerializerFunc[T any] func(*Serializer, *T) error -// DeserializerFn is the signature of customer deserializer functions. Use the +// DeserializerFunc is the signature of customer deserializer functions. Use the // [Deserialize] function to drive the [Deserializer]. Returning an error // results in the program panicking. -type DeserializerFn[T any] func(*Deserializer, *T) error +type DeserializerFunc[T any] func(*Deserializer, *T) error -// RegisterSerde attaches custom serialization and deserialization functions to +// Register attaches custom serialization and deserialization functions to // type T. // // Coroutine state is serialized and deserialized when calling [Context.Marshal] @@ -30,7 +30,7 @@ type DeserializerFn[T any] func(*Deserializer, *T) error // sync values do not. // // Custom serializer and deserializer functions can be attached to types using -// [RegisterSerde] to control how they are serialized, and possibly perform +// [Register] to control how they are serialized, and possibly perform // additional initialization on deserialization. Those functions are drivers for // [Serializer] and [Deserializer], that need to invoke [Serialize] and // [DeserializeTo] in order to actually perform serialization and @@ -40,9 +40,9 @@ type DeserializerFn[T any] func(*Deserializer, *T) error // result, slices sharing the same backing array are deserialized into one array // with two shared slices, just like the original state was. Elements between // length and capacity are also preserved. -func RegisterSerde[T any]( - serializer SerializerFn[T], - deserializer DeserializerFn[T]) { +func Register[T any]( + serializer SerializerFunc[T], + deserializer DeserializerFunc[T]) { registerSerde[T](types, serializer, deserializer) } @@ -67,13 +67,13 @@ func registerSerde[T any](tm *typemap, tm.attach(t, s, d) } -type serializerFn func(*Serializer, unsafe.Pointer) -type deserializerFn func(d *Deserializer, p unsafe.Pointer) +type serializerFunc func(*Serializer, unsafe.Pointer) +type deserializerFunc func(d *Deserializer, p unsafe.Pointer) type serde struct { id int - ser serializerFn - des deserializerFn + ser serializerFunc + des deserializerFunc } type typemap struct { @@ -89,7 +89,7 @@ func newTypemap() *typemap { return m } -func (m *typemap) attach(t reflect.Type, ser serializerFn, des deserializerFn) { +func (m *typemap) attach(t reflect.Type, ser serializerFunc, des deserializerFunc) { if ser == nil || des == nil { panic("both serializer and deserializer need to be provided") }