ochafik/nativelibs4java — Issue #200: Union regression bug
Author: AndreiSochirca
Created: 2011-11-12 18:15:13+00:00
State: open

Hi Olivier,

It seems the latest 0.7 snapshot has bug related to Union (it worked correctly with 0.4.1 version).

I have v4l2_format class that contains union.
The following exception is thrown while reading v4l2_format instance from native:

Caused by: java.lang.UnsupportedOperationException: Cannot change byte
length of non-signed integral fields (field type =
com.smaxe.bridj.linux.v4l2.core.v4l2_pix_format, target size = 32,
byteLength = 200)
at org.bridj.StructIO.fixIntegralTypeIOToMatchLength(StructIO.java:795)
at org.bridj.StructIO.readFieldsFromNative(StructIO.java:825)
... 18 more

```ruby
public class v4l2_format extends StructObject
{
/**
* fmt
*/
@Union
public static class fmt extends StructObject
{
/**
* Definition of an image format, see Chapter 2, used by video
capture and output devices.
*/
@Field(0)
public v4l2_pix_format pix;
/**
* Place holder for future extensions and custom (driver
defined) formats with type V4L2_BUF_TYPE_PRIVATE and higher.
*/
@Field(1)
@Array(200)
public Pointer raw_data;

/**
* Constructor.
*/
public fmt()
{
}

/**
* Constructor.
*
* @param ptr
*/
public fmt(Pointer ptr)
{
super(ptr);
}
}

// fields
/**
* Type of the data stream, see Table 3-2.
*/
@Field(0)
public int type;
@Field(1)
public fmt fmt;

/**
* Constructor.
*/
public v4l2_format()
{
}

/**
* Constructor.
*
* @param ptr
*/
public v4l2_format(Pointer ptr)
{
super(ptr);
}
}

public class v4l2_fmtdesc extends StructObject
{
// fields
/**
* Number of the format in the enumeration, set by the application.
* This is in no way related to the pixelformat field.
*/
@Field(0)
public int index;
/**
* Type of the data stream, set by the application.
* Only these types are valid here: V4L2_BUF_TYPE_VIDEO_CAPTURE,
* V4L2_BUF_TYPE_VIDEO_OUTPUT, V4L2_BUF_TYPE_VIDEO_OVERLAY, and custom
* (driver defined) types with code V4L2_BUF_TYPE_PRIVATE and higher.
*/
@Field(1)
public int type;
/**
* See Table 2.
*/
@Field(2)
public int flags;
/**
* Description of the format, a NUL-terminated ASCII string.
* This information is intended for the user, for example: "YUV 4:2:2".
*/
@Field(3)
@Array(32)
public Pointer description;
/**
* The image format identifier. This is a four character code as
computed by the v4l2_fourcc().
*/
@Field(4)
public int pixelformat;
/**
* Reserved for future extensions.
*/
@Field(5)
@Array(4)
public Pointer reserved;

/**
* Constructor.
*/
public v4l2_fmtdesc()
{
}

/**
* Constructor.
*
* @param ptr
*/
public v4l2_fmtdesc(Pointer ptr)
{
super(ptr);
}
}

```

Regards, Andrei.