Skip to content

Commit

Permalink
[Flink-11315] Make magic number in KvStateSerializer as a constant va…
Browse files Browse the repository at this point in the history
…lue to make more readable (apache#7482)

This closes apache#11315
  • Loading branch information
yuqi1129 authored and StefanRRichter committed Feb 7, 2019
1 parent 1b71e44 commit e6a318c
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
*/
public final class KvStateSerializer {

//The magic number is as a flag between key and namespace.
private static final int MAGIC_NUMBER = 42;
// ------------------------------------------------------------------------
// Generic serialization utils
// ------------------------------------------------------------------------
Expand Down Expand Up @@ -63,7 +65,7 @@ public static <K, N> byte[] serializeKeyAndNamespace(
DataOutputSerializer dos = new DataOutputSerializer(32);

keySerializer.serialize(key, dos);
dos.writeByte(42);
dos.writeByte(MAGIC_NUMBER);
namespaceSerializer.serialize(namespace, dos);

return dos.getCopyOfBuffer();
Expand Down Expand Up @@ -93,7 +95,7 @@ public static <K, N> Tuple2<K, N> deserializeKeyAndNamespace(
try {
K key = keySerializer.deserialize(dis);
byte magicNumber = dis.readByte();
if (magicNumber != 42) {
if (magicNumber != MAGIC_NUMBER) {
throw new IOException("Unexpected magic number " + magicNumber + ".");
}
N namespace = namespaceSerializer.deserialize(dis);
Expand Down

0 comments on commit e6a318c

Please sign in to comment.