Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #290 from scalecube/feature/issue-283-cluster-code…
…c-artifact-CR2arvy [CR287] Feature/issue 283 cluster codec artifact
- Loading branch information
Showing
19 changed files
with
401 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
cluster-api/src/main/java/io/scalecube/cluster/metadata/DefaultMetadataCodec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.scalecube.cluster.metadata; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.ObjectInputStream; | ||
import java.io.ObjectOutputStream; | ||
import java.nio.ByteBuffer; | ||
import reactor.core.Exceptions; | ||
|
||
public class DefaultMetadataCodec implements MetadataCodec { | ||
|
||
@Override | ||
public Object deserialize(ByteBuffer buffer) { | ||
byte[] bytes = buffer.array(); | ||
try (ObjectInputStream is = new ObjectInputStream(new ByteArrayInputStream(bytes))) { | ||
return is.readObject(); | ||
} catch (Exception e) { | ||
throw Exceptions.propagate(e); | ||
} | ||
} | ||
|
||
@Override | ||
public ByteBuffer serialize(Object metadata) { | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
try (ObjectOutputStream os = new ObjectOutputStream(baos)) { | ||
os.writeObject(metadata); | ||
os.flush(); | ||
return ByteBuffer.wrap(baos.toByteArray()); | ||
} catch (Exception e) { | ||
throw Exceptions.propagate(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.