X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=third-party%2Fatomix%2Fstorage%2Fsrc%2Ftest%2Fjava%2Fio%2Fatomix%2Fstorage%2Fjournal%2FByteArraySerdes.java;fp=third-party%2Fatomix%2Fstorage%2Fsrc%2Ftest%2Fjava%2Fio%2Fatomix%2Fstorage%2Fjournal%2FByteArraySerdes.java;h=79ce9097a3af945c424fc435e694473609ce1075;hp=0000000000000000000000000000000000000000;hb=014a5d10aa01fcb9b1a7f8bae97e13ca3b7aa698;hpb=0bacb5d7a91f1bc0fcd13763b1cdfcd74ed2e0e6 diff --git a/third-party/atomix/storage/src/test/java/io/atomix/storage/journal/ByteArraySerdes.java b/third-party/atomix/storage/src/test/java/io/atomix/storage/journal/ByteArraySerdes.java new file mode 100644 index 0000000000..79ce9097a3 --- /dev/null +++ b/third-party/atomix/storage/src/test/java/io/atomix/storage/journal/ByteArraySerdes.java @@ -0,0 +1,39 @@ +/* + * Copyright 2023 PANTHEON.tech, s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.atomix.storage.journal; + +import io.atomix.storage.journal.JournalSerdes.EntryInput; +import io.atomix.storage.journal.JournalSerdes.EntryOutput; +import io.atomix.storage.journal.JournalSerdes.EntrySerdes; +import java.io.IOException; + +final class ByteArraySerdes implements EntrySerdes { + @Override + public byte[] read(final EntryInput input) throws IOException { + int length = input.readVarInt(); + return length == 0 ? null : input.readBytes(length - 1); + } + + @Override + public void write(final EntryOutput output, final byte[] entry) throws IOException { + if (entry != null) { + output.writeVarInt(entry.length + 1); + output.writeBytes(entry); + } else { + output.writeVarInt(0); + } + } +}