-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a `replace` directive that makes it easier to serialize foreign types. Example usage with github.com/google/uuid ```go package main import "github.com/google/uuid" //go:generate msgp //msgp:replace uuid.UUID with:UUID type UUID [16]byte // Or like that //msgp:replace uuid.UUID with:[16]byte type User struct { ID uuid.UUID } ```
- Loading branch information
Showing
8 changed files
with
498 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package _generated | ||
|
||
//go:generate msgp | ||
//msgp:replace Any with:any | ||
//msgp:replace MapString with:CompatibleMapString | ||
//msgp:replace MapAny with:map[string]any | ||
//msgp:replace SliceString with:[]string | ||
//msgp:replace SliceInt with:CompatibleSliceInt | ||
//msgp:replace Array8 with:CompatibleArray8 | ||
//msgp:replace Array16 with:[16]byte | ||
//msgp:replace String with:string | ||
//msgp:replace Int with:CompatibleInt | ||
//msgp:replace Uint with:uint | ||
//msgp:replace Float32 with:CompatibleFloat32 | ||
//msgp:replace Float64 with:CompatibleFloat64 | ||
//msgp:replace Time with:time.Time | ||
//msgp:replace Duration with:time.Duration | ||
//msgp:replace StructA with:CompatibleStructA | ||
//msgp:replace StructB with:CompatibleStructB | ||
//msgp:replace StructC with:CompatibleStructC | ||
//msgp:replace StructD with:CompatibleStructD | ||
//msgp:replace StructI with:CompatibleStructI | ||
//msgp:replace StructS with:CompatibleStructS | ||
|
||
type ( | ||
CompatibleMapString map[string]string | ||
CompatibleArray8 [8]byte | ||
CompatibleInt int | ||
CompatibleFloat32 float32 | ||
CompatibleFloat64 float64 | ||
CompatibleSliceInt []Int | ||
|
||
// Doesn't work | ||
// CompatibleTime time.Time | ||
|
||
CompatibleStructA struct { | ||
StructB StructB | ||
Int Int | ||
} | ||
|
||
CompatibleStructB struct { | ||
StructC StructC | ||
Any Any | ||
Array8 Array8 | ||
} | ||
|
||
CompatibleStructC struct { | ||
StructD StructD | ||
Float64 Float32 | ||
Float32 Float64 | ||
} | ||
|
||
CompatibleStructD struct { | ||
Time Time | ||
Duration Duration | ||
MapString MapString | ||
} | ||
|
||
CompatibleStructI struct { | ||
Int *Int | ||
Uint *Uint | ||
} | ||
|
||
CompatibleStructS struct { | ||
Slice SliceInt | ||
} | ||
|
||
Dummy struct { | ||
StructA StructA | ||
StructI StructI | ||
StructS StructS | ||
Array16 Array16 | ||
Uint Uint | ||
String String | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package _generated | ||
|
||
import "time" | ||
|
||
// external types to test replace directive | ||
|
||
type ( | ||
MapString map[string]string | ||
MapAny map[string]any | ||
SliceString []String | ||
SliceInt []Int | ||
Array8 [8]byte | ||
Array16 [16]byte | ||
Int int | ||
Uint uint | ||
String string | ||
Float32 float32 | ||
Float64 float64 | ||
Time time.Time | ||
Duration time.Duration | ||
Any any | ||
|
||
StructA struct { | ||
StructB StructB | ||
Int Int | ||
} | ||
|
||
StructB struct { | ||
StructC StructC | ||
Any Any | ||
Array8 Array8 | ||
} | ||
|
||
StructC struct { | ||
StructD StructD | ||
Float64 Float32 | ||
Float32 Float64 | ||
} | ||
|
||
StructD struct { | ||
Time Time | ||
Duration Duration | ||
MapString MapString | ||
} | ||
|
||
StructI struct { | ||
Int *Int | ||
Uint *Uint | ||
} | ||
|
||
StructS struct { | ||
Slice SliceInt | ||
} | ||
) |
Oops, something went wrong.