2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.lifx.internal.fields;
15 import java.nio.ByteBuffer;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
20 * @author Tim Buckley - Initial contribution
21 * @author Karel Goderis - Initial contribution
24 public class MACAddressField extends Field<MACAddress> {
26 public MACAddressField() {
31 public int defaultLength() {
36 public MACAddress value(ByteBuffer bytes) {
37 byte[] data = new byte[length];
40 ByteBuffer buffer = ByteBuffer.wrap(data);
41 buffer.limit(length - 2);
42 return new MACAddress(buffer);
46 protected ByteBuffer bytesInternal(MACAddress value) {
47 return value.getBytes().duplicate();
51 public ByteBuffer bytes(MACAddress value) {
52 byte[] data = new byte[length];
53 ByteBuffer bytes = bytesInternal(value);
55 bytes.get(data, 0, bytes.limit());
56 ByteBuffer buf = ByteBuffer.wrap(data);