8000 Tags · tinylib/msgp · GitHub
[go: up one dir, main page]

Skip to content

Tags

Tags

v1.6.5

Toggle v1.6.5's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
edit: skip values in HasKey (#453)

HasKey read each key but not the value after it, so on the next pass it
read the value as a key. A key after the first was missed and a string
value matched as a key. Skip the value as locate and locateKV do.

v1.6.4

Toggle v1.6.4's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
msgp: Reader: reset limits on cached readers (#435)

A hand-written implementation of DecodeMsg may adjust the reader
limits inside msgp.CopyToJSON, msgp.Decode, and so forth.
Ensure that a Reader pulled from the pool has the same limits (zeros)
every time.

v1.6.3

Toggle v1.6.3's commit message
msgp: read.go: remove bogus Println

v1.6.2

Toggle v1.6.2's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Add (Reader).ReadBytesLimit (#432)

Simplifies generated code.

Fixes #425

Modify a few tests to allow wrapped errors.

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
0