blob: fc5c54070ae1ccacb08aa46e3e9e4eefbf7c21ea [file] [log] [blame]
Jian Liff8b9f92018-06-05 17:36:37 +09001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.openstacktelemetry.api;
17
18import java.nio.ByteBuffer;
19
20/**
21 * Abstraction of a codec capable for encoding/decoding arbitrary objects to/from ByteBuffer.
22 */
23public abstract class ByteBufferCodec<T> {
24
25 /**
26 * Encodes the specified entity into ByteBuffer.
27 *
28 * @param entity entity to encode
29 * @return ByteBuffer
30 * @throws java.lang.UnsupportedOperationException if the codec does not
31 * support encode operations
32 */
33 public ByteBuffer encode(T entity) {
34 throw new UnsupportedOperationException("encode() not supported");
35 }
36
37 /**
38 * Decodes the specified entity from ByteBuffer.
39 *
40 * @param buffer ByteBuffer to decode
41 * @return decoded entity
42 */
43 public T decode(ByteBuffer buffer) {
44 throw new UnsupportedOperationException("decode() not supported");
45 }
46}