function readPortSegment(path, offset, segment) { let length; segment.type = SEGMENT_TYPE.PORT; let extendedLinkAddress = getPortSegmentExtendedLinkAddressSizeBit(path, offset); let port = getPortSegmentPortIdentifier(path, offset);  if (extendedLinkAddress === false && port < 15) { segment.port = port; segment.linkAddress = Buffer.from(path.slice(offset + 1, offset + 2)); length = 2; } else if (extendedLinkAddress === true && port < 15) { segment.port = port; let linkAddressSize = path.readUInt8(offset + 1); segment.linkAddress = Buffer.from(path.slice(offset + 2, offset + 2 + linkAddressSize)); length = 2 + linkAddressSize; } else if (extendedLinkAddress === false && port === 15) { segment.port = path.readUInt16LE(offset + 1); segment.linkAddress = Buffer.from(path.slice(offset + 3, offset + 4)); length = 4; } else if (extendedLinkAddress === true && port === 15) { let linkAddressSize = path.readUInt8(offset + 1); segment.port = path.readUInt16LE(offset + 2); segment.linkAddress = Buffer.from(path.slice(offset + 4, offset + 4 + linkAddressSize)); length = 4 + linkAddressSize; }  return length % 2 === 0 ? length : length + 1; }
function readLogicalSegment(path, offset, segment) {
  segment.type = SEGMENT_TYPE.LOGICAL;
  const segmentByte = path.readUInt8(offset);
  const type = getBits(segmentByte, 2, 5) << 2;
  const format = getBits(segmentByte, 0, 2);

  segment.info = {
    type,
    typeDescription: LOGICAL_SEGMENT_TYPE_DESCRIPTIONS[type],
    format,
    formatDescription: LOGICAL_SEGMENT_FORMAT_DESCRIPTIONS[format]
  };

  let shift;
  switch (format) {
    case 0:
      segment.info.value = path.readUInt8(offset + 1);
      shift = 2;
      break;
    case 1:
      segment.info.value = path.readUInt16LE(offset + 2);
      shift = 4;
      break;
    case 2:
      segment.info.value = path.readUInt32LE(offset + 2);
      shift = 6;
      break;
    default:
      break;
  }

  return shift;
}