// Path: cip-core/src/main/java/com/digitalpetri/enip/cip/structs/ElectronicKey.java
// public final class ElectronicKey {
// 
//     private final int vendorId;
//     private final int deviceType;
//     private final int productCode;
//     private final boolean compatibilitySet;
//     private final short majorRevision;
//     private final short minorRevision;
// 
//     public ElectronicKey(int vendorId,
//                          int deviceType,
//                          int productCode,
//                          boolean compatibilitySet,
//                          short majorRevision,
//                          short minorRevision) {
// 
//         this.vendorId = vendorId;
//         this.deviceType = deviceType;
//         this.productCode = productCode;
//         this.compatibilitySet = compatibilitySet;
//         this.majorRevision = majorRevision;
//         this.minorRevision = minorRevision;
//     }
// 
//     public int getVendorId() {
//         return vendorId;
//     }
// 
//     public int getDeviceType() {
//         return deviceType;
//     }
// 
//     public int getProductCode() {
//         return productCode;
//     }
// 
//     public boolean isCompatibilitySet() {
//         return compatibilitySet;
//     }
// 
//     public short getMajorRevision() {
//         return majorRevision;
//     }
// 
//     public short getMinorRevision() {
//         return minorRevision;
//     }
// 
//     public static ByteBuf encode(ElectronicKey key, ByteBuf buffer) {
//         buffer.writeShort(key.getVendorId());
//         buffer.writeShort(key.getDeviceType());
//         buffer.writeShort(key.getProductCode());
// 
//         int majorRevisionAndCompatibility = key.isCompatibilitySet() ? 0x80 : 0x00;
//         majorRevisionAndCompatibility |= (key.getMajorRevision() & 0x7F);
// 
//         buffer.writeByte(majorRevisionAndCompatibility);
//         buffer.writeByte(key.getMinorRevision());
// 
//         return buffer;
//     }
// 
// }


import com.digitalpetri.enip.cip.structs.ElectronicKey;
import io.netty.buffer.ByteBuf;

        segmentByte |= (SEGMENT_TYPE << 5);
        segmentByte |= (segment.getType().getType() << 2);
        segmentByte |= segment.getFormat().getType();

        buffer.writeByte(segmentByte);

        if (padded && (segment.getFormat() == LogicalFormat.Bits_16 || segment.getFormat() == LogicalFormat.Bits_32)) {
            buffer.writeByte(0x00);
        }

        segment.encodeValue(buffer);

        return buffer;
    }

    private static ByteBuf encodeIntValue(LogicalFormat format, int value, ByteBuf buffer) {
        switch (format) {
            case Bits_8:
                return buffer.writeByte(value);
            case Bits_16:
                return buffer.writeShort(value);
            case Bits_32:
                return buffer.writeInt(value);
            case Reserved:
            default:
                throw new IllegalStateException("Reserved segment type not supported");
        }
    }

// Path: cip-core/src/main/java/com/digitalpetri/enip/cip/structs/ElectronicKey.java
// public final class ElectronicKey {
// 
//     private final int vendorId;
//     private final int deviceType;
//     private final int productCode;
//     private final boolean compatibilitySet;
//     private final short majorRevision;
//     private final short minorRevision;
// 
//     public ElectronicKey(int vendorId,
//                          int deviceType,
//                          int productCode,
//                          boolean compatibilitySet,
//                          short majorRevision,
//                          short minorRevision) {
// 
//         this.vendorId = vendorId;
//         this.deviceType = deviceType;
//         this.productCode = productCode;
//         this.compatibilitySet = compatibilitySet;
//         this.majorRevision = majorRevision;
//         this.minorRevision = minorRevision;
//     }
// 
//     public int getVendorId() {
//         return vendorId;
//     }
// 
//     public int getDeviceType() {
//         return deviceType;
//     }
// 
//     public int getProductCode() {
//         return productCode;
//     }
// 
//     public boolean isCompatibilitySet() {
//         return compatibilitySet;
//     }
// 
//     public short getMajorRevision() {
//         return majorRevision;
//     }
// 
//     public short getMinorRevision() {
//         return minorRevision;
//     }
// 
//     public static ByteBuf encode(ElectronicKey key, ByteBuf buffer) {
//         buffer.writeShort(key.getVendorId());
//         buffer.writeShort(key.getDeviceType());
//         buffer.writeShort(key.getProductCode());
// 
//         int majorRevisionAndCompatibility = key.isCompatibilitySet() ? 0x80 : 0x00;
//         majorRevisionAndCompatibility |= (key.getMajorRevision() & 0x7F);
// 
//         buffer.writeByte(majorRevisionAndCompatibility);
//         buffer.writeByte(key.getMinorRevision());
// 
//         return buffer;
//     }
// 
// }


// Path: cip-core/src/main/java/com/digitalpetri/enip/cip/epath/LogicalSegment.java
import com.digitalpetri.enip.cip.structs.ElectronicKey;
import io.netty.buffer.ByteBuf;


        segmentByte |= (SEGMENT_TYPE << 5);
        segmentByte |= (segment.getType().getType() << 2);
        segmentByte |= segment.getFormat().getType();

        buffer.writeByte(segmentByte);

        if (padded && (segment.getFormat() == LogicalFormat.Bits_16 || segment.getFormat() == LogicalFormat.Bits_32)) {
            buffer.writeByte(0x00);
        }

        segment.encodeValue(buffer);

        return buffer;
    }

    private static ByteBuf encodeIntValue(LogicalFormat format, int value, ByteBuf buffer) {
        switch (format) {
            case Bits_8:
                return buffer.writeByte(value);
            case Bits_16:
                return buffer.writeShort(value);
            case Bits_32:
                return buffer.writeInt(value);
            case Reserved:
            default:
                throw new IllegalStateException("Reserved segment type not supported");
        }
    }

    private static ByteBuf encodeKeyValue(LogicalFormat format, ElectronicKey value, ByteBuf buffer) {