2 * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.common;
10 import java.io.Externalizable;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14 import java.nio.charset.StandardCharsets;
17 * Serialization proxy for {@link RevisionUnion}.
19 final class RUv1 implements Externalizable {
21 private static final long serialVersionUID = 1L;
22 private static final int LENGTH = Revision.MAX_VALUE.unionString().length();
24 private String dateString;
26 @SuppressWarnings("checkstyle:redundantModifier")
31 RUv1(final String dateString) {
32 final int length = dateString.length();
33 if (length != 0 && length != LENGTH) {
34 throw new IllegalArgumentException("Unexpected string length " + length);
36 this.dateString = dateString;
40 public void writeExternal(final ObjectOutput out) throws IOException {
41 final var length = dateString.length();
42 out.writeByte(length);
44 out.write(dateString.getBytes(StandardCharsets.US_ASCII));
49 public void readExternal(final ObjectInput in) throws IOException {
50 final int length = in.readByte();
51 if (length == LENGTH) {
52 final var bytes = new byte[length];
54 dateString = new String(bytes, StandardCharsets.US_ASCII);
55 } else if (length == 0) {
58 throw new IOException("Unexpected byte length " + length);
63 private Object readResolve() {
64 return RevisionUnion.of(dateString);