Skip to content

Tags: tinylib/msgp

Tags

v1.6.1

Toggle v1.6.1's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Fix WriteBytes/WriteString/WriteStringFromBytes limit (#429)

v1.6.0

Toggle v1.6.0's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
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.

v1.5.0

Toggle v1.5.0's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
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
}
```

v1.4.0

Toggle v1.4.0's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Clarify -unexported flag. (#402)

Fixes #251

v1.3.0

Toggle v1.3.0's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Add setof helper package (#391)

Package setof allows serializing sets map[T]struct{} as arrays.

Nil maps are preserved as a nil value on stream.

A deterministic (sorted) version is available, with slightly lower performance.

v1.2.5

Toggle v1.2.5's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
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

v1.2.4

Toggle v1.2.4's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
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

v1.2.3

Toggle v1.2.3's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Fix allownil on maps elements (#375)

* Fix allownil on maps elements
* Also set for primitives.

Similar to #374 map `[]byte` elements would also inherit allownil unintentionally.

v1.2.2

Toggle v1.2.2's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
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

v1.2.1

Toggle v1.2.1's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
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.