2 * Copyright (c) 2013 Cisco Systems, Inc. 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.protocol.pcep.ietf.stateful07;
10 import org.opendaylight.protocol.pcep.impl.tlv.TlvUtil;
11 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
12 import org.opendaylight.protocol.pcep.spi.TlvParser;
13 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
14 import org.opendaylight.protocol.util.ByteArray;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.error.code.tlv.LspErrorCode;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.error.code.tlv.LspErrorCodeBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
20 * Parser for {@link LspErrorCode}
22 public final class Stateful07LspUpdateErrorTlvParser implements TlvParser, TlvSerializer {
24 public static final int TYPE = 20;
26 private static final int UPDATE_ERR_CODE_LENGTH = 4;
29 public LspErrorCode parseTlv(final byte[] buffer) throws PCEPDeserializerException {
30 return new LspErrorCodeBuilder().setErrorCode(ByteArray.bytesToLong(buffer)).build();
34 public byte[] serializeTlv(final Tlv tlv) {
36 throw new IllegalArgumentException("LspErrorCodeTlv is mandatory.");
38 final LspErrorCode lsp = (LspErrorCode) tlv;
39 return TlvUtil.formatTlv(TYPE, ByteArray.longToBytes(lsp.getErrorCode(), UPDATE_ERR_CODE_LENGTH));