package info.frostfs.sdk.mappers; import com.google.protobuf.CodedOutputStream; import com.google.protobuf.InvalidProtocolBufferException; import frostfs.session.Types; import java.io.IOException; import static java.util.Objects.isNull; public class SessionMapper { private SessionMapper() { } public static byte[] serialize(Types.SessionToken token) { if (isNull(token)) { throw new IllegalArgumentException("Token is not present"); } try { byte[] bytes = new byte[token.getSerializedSize()]; CodedOutputStream stream = CodedOutputStream.newInstance(bytes); token.writeTo(stream); return bytes; } catch (IOException exp) { throw new IllegalArgumentException(exp.getMessage()); } } public static Types.SessionToken deserializeSessionToken(byte[] bytes) { if (isNull(bytes) || bytes.length == 0) { throw new IllegalArgumentException("Token is not present"); } try { return Types.SessionToken.newBuilder().mergeFrom(bytes).build(); } catch (InvalidProtocolBufferException exp) { throw new IllegalArgumentException(exp.getMessage()); } } }