You've already forked hex-microservice
mirror of
https://github.com/tensor-programming/hex-microservice.git
synced 2026-05-02 20:12:11 +02:00
26 lines
640 B
Go
26 lines
640 B
Go
package msgpack
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"github.com/tensor-programming/hex-microservice/shortener"
|
|
"github.com/vmihailenco/msgpack"
|
|
)
|
|
|
|
type Redirect struct{}
|
|
|
|
func (r *Redirect) Decode(input []byte) (*shortener.Redirect, error) {
|
|
redirect := &shortener.Redirect{}
|
|
if err := msgpack.Unmarshal(input, redirect); err != nil {
|
|
return nil, errors.Wrap(err, "serializer.Redirect.Decode")
|
|
}
|
|
return redirect, nil
|
|
}
|
|
|
|
func (r *Redirect) Encode(input *shortener.Redirect) ([]byte, error) {
|
|
rawMsg, err := msgpack.Marshal(input)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "serializer.Redirect.Encode")
|
|
}
|
|
return rawMsg, nil
|
|
}
|