Documentation
¶
Index ¶
- Constants
- type DynamicType
- type Serializer
- func (s *Serializer[T]) FromB64Bytes(b []byte) *Serializer[T]
- func (s *Serializer[T]) FromB64String(str string) *Serializer[T]
- func (s *Serializer[T]) FromBytes(b []byte) *Serializer[T]
- func (s *Serializer[T]) FromDynamicType(t any) *Serializer[T]
- func (s *Serializer[T]) FromJsonString(str string) *Serializer[T]
- func (s *Serializer[T]) FromString(str string) *Serializer[T]
- func (s *Serializer[T]) FromT(t T) *Serializer[T]
- func (s *Serializer[T]) ToB64Bytes() ([]byte, error)
- func (s *Serializer[T]) ToB64String() (string, error)
- func (s *Serializer[T]) ToBytes() ([]byte, error)
- func (s *Serializer[T]) ToDynamicType(dynamicType DynamicType, typ any) (any, error)
- func (s *Serializer[T]) ToJsonString() (string, error)
- func (s *Serializer[T]) ToString() (string, error)
- func (s *Serializer[T]) ToT() (T, error)
Constants ¶
const ( B64String DynamicType = "b64string" JSONString DynamicType = "jsonstring" String DynamicType = "string" Bytes DynamicType = "bytes" B64Bytes DynamicType = "b64bytes" Struct DynamicType = "struct" Reflect DynamicType = "reflection" // if provided, T is used // custom prefix added to encoded b64 strings to prevent possible misidentification of b64 strings when using Dynamic lookups B64Prefix string = "b64:" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DynamicType ¶
type DynamicType string
type Serializer ¶
type Serializer[T any] struct { // contains filtered or unexported fields }
func NewSerializer ¶
func NewSerializer[T any]() *Serializer[T]
func (*Serializer[T]) FromB64Bytes ¶
func (s *Serializer[T]) FromB64Bytes(b []byte) *Serializer[T]
func (*Serializer[T]) FromB64String ¶
func (s *Serializer[T]) FromB64String(str string) *Serializer[T]
func (*Serializer[T]) FromBytes ¶
func (s *Serializer[T]) FromBytes(b []byte) *Serializer[T]
func (*Serializer[T]) FromDynamicType ¶
func (s *Serializer[T]) FromDynamicType(t any) *Serializer[T]
FromDynamicType will attempt to infer T and call the appropriate From method. If the type is not inferable, it will return the serializer as is, which will result in an error when calling a To function.
func (*Serializer[T]) FromJsonString ¶
func (s *Serializer[T]) FromJsonString(str string) *Serializer[T]
func (*Serializer[T]) FromString ¶
func (s *Serializer[T]) FromString(str string) *Serializer[T]
func (*Serializer[T]) FromT ¶
func (s *Serializer[T]) FromT(t T) *Serializer[T]
func (*Serializer[T]) ToB64Bytes ¶
func (s *Serializer[T]) ToB64Bytes() ([]byte, error)
ToB64Bytes encodes the from input as a b64 encoded byte slice
func (*Serializer[T]) ToB64String ¶
func (s *Serializer[T]) ToB64String() (string, error)
ToB64String converts the from input as a b64 encoded string
func (*Serializer[T]) ToBytes ¶
func (s *Serializer[T]) ToBytes() ([]byte, error)
ToBytes converts the from input as a byte slice
func (*Serializer[T]) ToDynamicType ¶
func (s *Serializer[T]) ToDynamicType(dynamicType DynamicType, typ any) (any, error)
ToDynamicType allows a single method to dynamically determine the toType depending on dynamic type. If "reflect" is provided, then parameter typ will be used to determine the target type to convert to. This will be a best-effort conversion.
func (*Serializer[T]) ToJsonString ¶
func (s *Serializer[T]) ToJsonString() (string, error)
ToJsonString encodes the from input as a json string
func (*Serializer[T]) ToString ¶
func (s *Serializer[T]) ToString() (string, error)
ToString encodes the from input as a string