2 * Copyright 2011, Big Switch Networks, Inc.
3 * Originally created by David Erickson & Rob Sherwood, Stanford University
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License. You may obtain
7 * a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations
18 package org.openflow.protocol.vendor;
20 import org.jboss.netty.buffer.ChannelBuffer;
23 * Basic implementation of OFVendorData that just treats the data as a
24 * byte array. This is used if there's an OFVendor message where there's
25 * no registered OFVendorId or no specific OFVendorDataType that can be
26 * determined from the data.
28 * @author Rob Vaterlaus (rob.vaterlaus@bigswitch.com)
30 public class OFByteArrayVendorData implements OFVendorData {
32 protected byte[] bytes;
35 * Construct vendor data with an empty byte array.
37 public OFByteArrayVendorData() {
41 * Construct vendor data with the specified byte array.
44 public OFByteArrayVendorData(byte[] bytes) {
49 * Get the associated byte array for this vendor data.
50 * @return the byte array containing the raw vendor data.
52 public byte[] getBytes() {
57 * Set the byte array for the vendor data.
58 * @param bytes the raw byte array containing the vendor data.
60 public void setBytes(byte[] bytes) {
65 * Get the length of the vendor data. In this case it's just then length
66 * of the underlying byte array.
67 * @return the length of the vendor data
70 public int getLength() {
71 return (bytes != null) ? bytes.length : 0;
75 * Read the vendor data from the ChannelBuffer into the byte array.
76 * @param data the channel buffer from which we're deserializing
77 * @param length the length to the end of the enclosing message
80 public void readFrom(ChannelBuffer data, int length) {
81 bytes = new byte[length];
82 data.readBytes(bytes);
86 * Write the vendor data bytes to the ChannelBuffer
87 * @param data the channel buffer to which we're serializing
90 public void writeTo(ChannelBuffer data) {
92 data.writeBytes(bytes);