Search in sources :

Example 1 with DataOutputSerializer

use of org.apache.flink.core.memory.DataOutputSerializer in project flink by apache.

the class SimpleVersionedSerializationTest method testSerializationRoundTrip.

@Test
public void testSerializationRoundTrip() throws IOException {
    final SimpleVersionedSerializer<String> utfEncoder = new TestStringSerializer();
    final String testString = "dugfakgs";
    final DataOutputSerializer out = new DataOutputSerializer(32);
    SimpleVersionedSerialization.writeVersionAndSerialize(utfEncoder, testString, out);
    final byte[] outBytes = out.getCopyOfBuffer();
    final byte[] bytes = SimpleVersionedSerialization.writeVersionAndSerialize(utfEncoder, testString);
    assertArrayEquals(bytes, outBytes);
    final DataInputDeserializer in = new DataInputDeserializer(bytes);
    final String deserialized = SimpleVersionedSerialization.readVersionAndDeSerialize(utfEncoder, in);
    final String deserializedFromBytes = SimpleVersionedSerialization.readVersionAndDeSerialize(utfEncoder, outBytes);
    assertEquals(testString, deserialized);
    assertEquals(testString, deserializedFromBytes);
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) DataInputDeserializer(org.apache.flink.core.memory.DataInputDeserializer) Test(org.junit.Test)

Example 2 with DataOutputSerializer

use of org.apache.flink.core.memory.DataOutputSerializer in project flink by apache.

the class SimpleVersionedSerializationTest method testListSerializationRoundTrip.

@Test
public void testListSerializationRoundTrip() throws IOException {
    final SimpleVersionedSerializer<String> utfEncoder = new TestStringSerializer();
    final List<String> datums = ImmutableList.of("beeep!", "beep!!!");
    final DataOutputSerializer out = new DataOutputSerializer(32);
    SimpleVersionedSerialization.writeVersionAndSerializeList(utfEncoder, datums, out);
    final byte[] outBytes = out.getCopyOfBuffer();
    final DataInputDeserializer in = new DataInputDeserializer(outBytes);
    final List<String> deserialized = SimpleVersionedSerialization.readVersionAndDeserializeList(utfEncoder, in);
    assertEquals(datums, deserialized);
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) DataInputDeserializer(org.apache.flink.core.memory.DataInputDeserializer) Test(org.junit.Test)

Example 3 with DataOutputSerializer

use of org.apache.flink.core.memory.DataOutputSerializer in project flink by apache.

the class FileWriterBucketStateSerializer method serialize.

@Override
public byte[] serialize(FileWriterBucketState state) throws IOException {
    DataOutputSerializer out = new DataOutputSerializer(256);
    out.writeInt(MAGIC_NUMBER);
    serializeV3(state, out);
    return out.getCopyOfBuffer();
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer)

Example 4 with DataOutputSerializer

use of org.apache.flink.core.memory.DataOutputSerializer in project flink by apache.

the class CompactorRequestSerializer method serialize.

@Override
public byte[] serialize(CompactorRequest request) throws IOException {
    DataOutputSerializer out = new DataOutputSerializer(256);
    out.writeInt(MAGIC_NUMBER);
    serializeV1(request, out);
    return out.getCopyOfBuffer();
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer)

Example 5 with DataOutputSerializer

use of org.apache.flink.core.memory.DataOutputSerializer in project flink by apache.

the class FileSinkCommittableSerializer method serialize.

@Override
public byte[] serialize(FileSinkCommittable committable) throws IOException {
    DataOutputSerializer out = new DataOutputSerializer(256);
    out.writeInt(MAGIC_NUMBER);
    serializeV2(committable, out);
    return out.getCopyOfBuffer();
}
Also used : DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer)

Aggregations

DataOutputSerializer (org.apache.flink.core.memory.DataOutputSerializer)63 DataInputDeserializer (org.apache.flink.core.memory.DataInputDeserializer)15 Test (org.junit.Test)15 IOException (java.io.IOException)10 ByteBuffer (java.nio.ByteBuffer)6 List (java.util.List)4 IntSerializer (org.apache.flink.api.common.typeutils.base.IntSerializer)4 StringSerializer (org.apache.flink.api.common.typeutils.base.StringSerializer)4 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)4 ArrayList (java.util.ArrayList)3 IntStream (java.util.stream.IntStream)3 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)3 TypeSerializer (org.apache.flink.api.common.typeutils.TypeSerializer)3 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Function (java.util.function.Function)2 Stream (java.util.stream.Stream)2 ValueState (org.apache.flink.api.common.state.ValueState)2 ValueStateDescriptor (org.apache.flink.api.common.state.ValueStateDescriptor)2