func Decode(encoded *v0.Zookie) (*zookie.DecodedZookie, error) {
	if encoded == nil {
		return nil, fmt.Errorf(errDecodeError, ErrNilZookie)
	}
	decodedBytes, err := base64.StdEncoding.DecodeString(encoded.Token)
	if err != nil {
		return nil, fmt.Errorf(errDecodeError, err)
	}
	decoded := &zookie.DecodedZookie{}
	if err := proto.Unmarshal(decodedBytes, decoded); err != nil {
		return nil, fmt.Errorf(errDecodeError, err)
	}
	return decoded, nil
}
Decode converts an encoded zookie to its decoded version.
package zookie
import (
	"encoding/base64"
	"errors"
	"fmt"
	v0 "github.com/authzed/authzed-go/proto/authzed/api/v0"
	"github.com/shopspring/decimal"
	"google.golang.org/protobuf/proto"
	zookie "github.com/authzed/spicedb/internal/proto/impl/v1"
)
const (
	errEncodeError = "error encoding zookie: %w"
	errDecodeError = "error decoding zookie: %w"
)
var ErrNilZookie = errors.New("zookie pointer was nil")
func NewFromRevision(revision decimal.Decimal) *v0.Zookie {
	toEncode := &zookie.DecodedZookie{
		Version: 2,
		VersionOneof: &zookie.DecodedZookie_V2{
			V2: &zookie.DecodedZookie_V2Zookie{
				Revision: revision.String(),
			},
		},
	}
	encoded, err := Encode(toEncode)
	if err != nil {
		panic(fmt.Errorf(errEncodeError, err))
	}
	return encoded
}
func Encode(decoded *zookie.DecodedZookie) (*v0.Zookie, error) {
	marshalled, err := proto.Marshal(decoded)
	if err != nil {
		return nil, fmt.Errorf(errEncodeError, err)
	}
	return &v0.Zookie{
		Token: base64.StdEncoding.EncodeToString(marshalled),
	}, nil
}