private static byte[] serializeKey(Key key) throws StoreIOException {
try {
KeyData data = key.buildData().build();
byte[] bytes = new byte[data.getSerializedSize()];
CodedOutputStream cos = CodedOutputStream.newInstance(bytes);
data.writeTo(cos);
cos.checkNoSpaceLeft();
return bytes;
} catch (Exception ex) {
throw new StoreIOException(
StoreIOException.Reason.SERIALIZATION_ERROR, ex);