if(readSignatureMarker) {
readSignatureMarker = false;
- byte marker = input.readByte();
- if(marker != NormalizedNodeOutputStreamWriter.SIGNATURE_MARKER) {
+ final byte marker = input.readByte();
+ if (marker != TokenTypes.SIGNATURE_MARKER) {
throw new InvalidNormalizedNodeStreamException(String.format(
"Invalid signature marker: %d", marker));
}
- input.readShort(); // read the version - not currently used/needed.
+ final short version = input.readShort();
+ if (version != TokenTypes.LITHIUM_VERSION) {
+ throw new InvalidNormalizedNodeStreamException(String.format("Unhandled stream version %s", version));
+ }
}
}
private String readCodedString() throws IOException {
byte valueType = input.readByte();
- if(valueType == NormalizedNodeOutputStreamWriter.IS_CODE_VALUE) {
+ if(valueType == TokenTypes.IS_CODE_VALUE) {
return codedStringMap.get(input.readInt());
- } else if(valueType == NormalizedNodeOutputStreamWriter.IS_STRING_VALUE) {
+ } else if(valueType == TokenTypes.IS_STRING_VALUE) {
String value = input.readUTF().intern();
codedStringMap.put(Integer.valueOf(codedStringMap.size()), value);
return value;
private static final Logger LOG = LoggerFactory.getLogger(NormalizedNodeOutputStreamWriter.class);
- static final byte SIGNATURE_MARKER = (byte) 0xab;
- static final short CURRENT_VERSION = (short) 1;
-
- static final byte IS_CODE_VALUE = 1;
- static final byte IS_STRING_VALUE = 2;
- static final byte IS_NULL_VALUE = 3;
-
private final DataOutput output;
private final Map<String, Integer> stringCodeMap = new HashMap<>();
private void writeSignatureMarkerAndVersionIfNeeded() throws IOException {
if(!wroteSignatureMarker) {
- output.writeByte(SIGNATURE_MARKER);
- output.writeShort(CURRENT_VERSION);
+ output.writeByte(TokenTypes.SIGNATURE_MARKER);
+ output.writeShort(TokenTypes.LITHIUM_VERSION);
wroteSignatureMarker = true;
}
}
private void writeCodedString(String key) throws IOException {
Integer value = stringCodeMap.get(key);
if(value != null) {
- output.writeByte(IS_CODE_VALUE);
+ output.writeByte(TokenTypes.IS_CODE_VALUE);
output.writeInt(value);
} else {
if(key != null) {
- output.writeByte(IS_STRING_VALUE);
+ output.writeByte(TokenTypes.IS_STRING_VALUE);
stringCodeMap.put(key, Integer.valueOf(stringCodeMap.size()));
output.writeUTF(key);
} else {
- output.writeByte(IS_NULL_VALUE);
+ output.writeByte(TokenTypes.IS_NULL_VALUE);
}
}
}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.cluster.datastore.node.utils.stream;
+
+final class TokenTypes {
+ private TokenTypes() {
+ throw new UnsupportedOperationException();
+ }
+
+ static final byte SIGNATURE_MARKER = (byte) 0xab;
+
+ /**
+ * Original stream version. Uses a per-stream dictionary for strings. QNames are serialized as three strings.
+ */
+ static final short LITHIUM_VERSION = 1;
+
+ // Tokens supported in LITHIUM_VERSION
+ static final byte IS_CODE_VALUE = 1;
+ static final byte IS_STRING_VALUE = 2;
+ static final byte IS_NULL_VALUE = 3;
+}