Skip to content

Commit

Permalink
More renames
Browse files Browse the repository at this point in the history
  • Loading branch information
pelletier committed Sep 27, 2023
1 parent 42967af commit ce350a0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions types/serde_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -226,7 +226,7 @@ func TestReflectCustom(t *testing.T) {
y Y
}

RegisterSerde[int](ser, des)
Register[int](ser, des)

x := X{
foo: "test",
Expand All @@ -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"
Expand All @@ -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)
Expand All @@ -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 {
Expand Down
28 changes: 14 additions & 14 deletions types/typemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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)
}

Expand All @@ -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 {
Expand All @@ -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")
}
Expand Down

0 comments on commit ce350a0

Please sign in to comment.