]> git.basschouten.com Git - openhab-addons.git/blob
56e1ad5f34937be8fb5399d4ecc45739cfe9cdba
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.lifx.internal.fields;
14
15 import java.nio.ByteBuffer;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  * @author Tim Buckley - Initial contribution
21  */
22 @NonNullByDefault
23 public class ByteField extends Field<ByteBuffer> {
24
25     public ByteField() {
26     }
27
28     public ByteField(int length) {
29         super(length);
30     }
31
32     @Override
33     public int defaultLength() {
34         return 2;
35     }
36
37     @Override
38     public ByteBuffer value(ByteBuffer bytes) {
39         byte[] data = new byte[length];
40         bytes.get(data);
41
42         return ByteBuffer.wrap(data);
43     }
44
45     @Override
46     public ByteBuffer bytesInternal(ByteBuffer value) {
47         return value;
48     }
49 }