Tags: tinylib/msgp
Tags
Update fuzz tests (#428) Decided to make ReadArray always stop after an error. There is a too high risk of running into an infinite loop. Added size checks for (Writer.)WriteBytes/WriteString/WriteStringFromBytes Add panic recovery to binary marshal helpers.
feat: Support generic types (#410) This adds support for generic types. Say you have `type Foo[T any] struct`, you must add a constraint that it can be handled properly. The constraint is added with a built-in `type Foo[T any, _ msgp.RTFor[T]`. If `T` supports serialization this will work. Multiple types can be added, but each must have the constraint. Nested of types are supported. For example: ```go type Foo[T any, P msgp.RTFor[T]] struct { X Bar[T, P] `msg:",allownil"` } type Bar[T any, _ msgp.RTFor[T]] struct {...} ``` Notice how `P` can be used for a nested generic type. ## Limitations * Types cannot be primitives since they must support marshalling. It can however be an `type Int64 int` with generation should still work * Since we cannot reliably create instances with arbitrary types there are no tests. * The `msgp.RTFor[T]` type shouldn't be used for types in the struct since new instances cannot be created and can cause a runtime crash. * There will be warnings like: `warn: generics.go: GenericTest: A: possible non-local identifier: T`. * Some directives may exhibit unexpected behaviour. Not tested too deeply. ## Example ```go // MyStruct can be instantiated with any type T that supports marshaling. // T must be the base type and not a pointer to work. type MyStruct[T any, P msgp.RTFor[T]] struct { // Direct use of T A T C []T D map[string]T // T used for another generic. E MyStruct2[T, P, string] F []MyStruct2[T, P, string] G map[string]MyStruct2[T, P, string] // Same with pointers AP *T CP []*T DP map[string]*T EP *MyStruct2[T, P, string] FP []*MyStruct2[T, P, string] GP map[string]*MyStruct2[T, P, string] } // MyStruct2 can be used inside MyStruct. type MyStruct2[T any, P msgp.RTFor[T], B any] struct { A T } ```
Ignore complexity of children in maps/slices (#382) When considering inlining maps/slices/arrays, apply a fixed cost and ignore the cost of the children. If children are too expensive, they will not be inlined, but it shouldn't affect whether the map itself is inlined. This only really applies when a map or slice type is aliased, otherwise it will not be considered for inlining. Fixes #381
Add "newtime" directive to use official messagepack time format (#378) This adds `msgp:newtime` file directive that will encode all time fields using the -1 extension as defined in the [(revised) messagepack spec](https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type) ReadTime/ReadTimeBytes will now support both types natively, and will accept either as input. Extensions should remain unaffected. Fixes #300
Add native json.Number support (#364) Allow encoding and decoding of `json.Number` values, either as struct members or as interface members. Numbers will be encoded as integer, if possible, otherwise float64/float32 is used. The zero value json.Number will be encoded as 0. It is possible to encode as string with `//msgp:replace json.Number with:string`. Fixes #292
Add recursion limit for dynamic code (#358) Prevent stack exhaustion on: Decoder: * CopyNext * Skip * ReadIntf * ReadMapStrIntf * WriteToJSON Standalone: * Skip * ReadMapStrIntfBytes * ReadIntfBytes * CopyToJSON * UnmarshalAsJSON Limit is set to 100K recursive map/slice operations.
PreviousNext