29 lines
935 B
Java
29 lines
935 B
Java
package info.frostfs.sdk.mappers;
|
|
|
|
import com.google.protobuf.CodedOutputStream;
|
|
import com.google.protobuf.InvalidProtocolBufferException;
|
|
import frostfs.session.Types;
|
|
|
|
import java.io.IOException;
|
|
|
|
public class SessionMapper {
|
|
|
|
public static byte[] serialize(Types.SessionToken token) {
|
|
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) {
|
|
try {
|
|
return Types.SessionToken.newBuilder().mergeFrom(bytes).build();
|
|
} catch (InvalidProtocolBufferException exp) {
|
|
throw new IllegalArgumentException(exp.getMessage());
|
|
}
|
|
}
|
|
}
|