MCPcopy
hub / github.com/tinylib/msgp / DecoderFromBytes

Function DecoderFromBytes

msgp/iter.go:352–359  ·  view source on GitHub ↗

DecoderFromBytes allows augmenting any type with an UnmarshalMsg method into a method that reads from []byte and returns a T. Provide an instance of T. This value isn't used. See ReadArrayBytes or ReadMapBytes "struct" examples for usage.

(_ T)

Source from the content-addressed store, hash-verified

350// Provide an instance of T. This value isn't used.
351// See ReadArrayBytes or ReadMapBytes "struct" examples for usage.
352func DecoderFromBytes[T any, PT UnmarshalPtr[T]](_ T) func([]byte) (T, []byte, error) {
353 return func(b []byte) (T, []byte, error) {
354 var t T
355 tPtr := PT(&t)
356 b, err := tPtr.UnmarshalMsg(b)
357 return t, b, err
358 }
359}
360
361// FlexibleMarshaler is a constraint for types where either T or *T implements Marshaler
362type FlexibleMarshaler[T any] interface {

Calls 1

UnmarshalMsgMethod · 0.65

Tested by 3

Used in the wild real call sites across dependent graphs

searching dependent graphs…