package com.qianwen.core.redis.serializer; import io.protostuff.LinkedBuffer; import io.protostuff.ProtostuffIOUtil; import io.protostuff.Schema; import io.protostuff.runtime.RuntimeSchema; import com.qianwen.core.tool.utils.ObjectUtil; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.SerializationException; /* loaded from: blade-starter-redis-9.3.0.0-SNAPSHOT.jar:org/springblade/core/redis/serializer/ProtoStuffSerializer.class */ public class ProtoStuffSerializer implements RedisSerializer { private final Schema schema = RuntimeSchema.getSchema(BytesWrapper.class); public byte[] serialize(Object object) throws SerializationException { if (object == null) { return null; } LinkedBuffer buffer = LinkedBuffer.allocate(512); try { byte[] byteArray = ProtostuffIOUtil.toByteArray(new BytesWrapper(object), this.schema, buffer); buffer.clear(); return byteArray; } catch (Throwable th) { buffer.clear(); throw th; } } public Object deserialize(byte[] bytes) throws SerializationException { if (ObjectUtil.isEmpty(bytes)) { return null; } BytesWrapper wrapper = new BytesWrapper<>(); ProtostuffIOUtil.mergeFrom(bytes, wrapper, this.schema); return wrapper.getValue(); } }