Skip to content

Package: BinaryPayloadCodec

BinaryPayloadCodec

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017, 2020 Red Hat Inc and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License v1.0
6: * which accompanies this distribution, and is available at
7: * http://www.eclipse.org/legal/epl-v10.html
8: *
9: * Contributors:
10: * Red Hat Inc - initial API and implementation
11: *******************************************************************************/
12: package org.eclipse.kapua.client.gateway;
13:
14: import java.nio.ByteBuffer;
15:
16: /**
17: * A codec for BLOB based payload transports
18: */
19: public interface BinaryPayloadCodec {
20:
21: /**
22: * Encode a {@link Payload} structure into a BLOB
23: * <p>
24: * The payload information gets encoded into a blob and appended at the end of the
25: * provided buffer. If the provided buffer is {@code null} a new buffer will be allocated.
26: * </p>
27: * <p>
28: * <b>Note:</b> The returning buffer may not be the same as the provided buffer. If the
29: * provided buffer has less remaining space than required a new buffer is allocated and
30: * returned, which will contain both the existing content as well as the newly appended.
31: * </p>
32: *
33: * @param payload
34: * The payload to encode, must not be {@code null}
35: * @param buffer
36: * An optional buffer to append the output to, may be {@code null}
37: * @return A buffer with the appended payload output, must never be {@code null}
38: * @throws Exception
39: * if anything goes wrong
40: */
41: public ByteBuffer encode(Payload payload, ByteBuffer buffer) throws Exception;
42:
43: /**
44: * Decode a {@link Payload} structure from the provided BLOB
45: *
46: * @param buffer
47: * The buffer to read from, must not be {@code null}
48: * @return the decoded payload structure, may be {@code null}
49: * @throws Exception
50: * if anything goes wrong
51: */
52: public Payload decode(ByteBuffer buffer) throws Exception;
53: }