go-redis/cache

Protobuf unmarshalling

Closed this issue · 2 comments

encoding/binary package doesn't have a possibility to unmarshal bytes to google protobuf generated messages.
Error: cannot unmarshal array into Go struct field Attribute.attributes.values of type structpb.Value
( golang/protobuf discussion: golang/protobuf#1019)

Could you please provide a possibility to get raw bytes from the cache ie make getBytes method public (https://github.com/go-redis/cache/blob/master/cache.go#L195)

Ok
I was able to specify my own Unmarshaler, but it looks weird

func unmarshaler(data []byte, struc interface{}) error {
        protoResponse, ok := struc.(*proto.MyProtoGeneratedType)
	if ok {
		unmarhshaller := &jsonpb.Unmarshaler{AllowUnknownFields: true}
		err := unmarhshaller.Unmarshal(bytes.NewReader(data), protoResponse)
		if err != nil {
			return err
		}
		return nil
	}
	json.Unmarshal(data, struc)
	return nil
}

There are no plans to support custom encoding. It is better to fork it or use something more stable & versatile.