Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: [R/S] preliminary support for [bytes! <size>] definitions in struct #3001

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Oldes
Copy link
Contributor

@Oldes Oldes commented Aug 27, 2017

When working with system and external binding, you very quickly notice, that many structs use byte arrays... for example Windows Socket data:

typedef struct WSAData {
  WORD           wVersion;
  WORD           wHighVersion;
  char           szDescription[WSADESCRIPTION_LEN+1];
  char           szSystemStatus[WSASYS_STATUS_LEN+1];
  unsigned short iMaxSockets;
  unsigned short iMaxUdpDg;
  char FAR       *lpVendorInfo;
} WSADATA, *LPWSADATA;

Or libmpg123's id3 tag:

typedef struct
{
	char tag[3];         /**< Always the string "TAG", the classic intro. */
	char title[30];      /**< Title string.  */
	char artist[30];     /**< Artist string. */
	char album[30];      /**< Album string. */
	char year[4];        /**< Year string. */
	char comment[30];    /**< Comment string. */
	unsigned char genre; /**< Genre index. */
} mpg123_id3v1;

To use these structs from current Red/System is possible, but not easy, so I tried to extend Red/System as you can see in this PR, so for the second example I could use:

mpg123_id3v1!: alias struct! [
	tag     [bytes!  3] ; Always the string "TAG", the classic intro.
	title   [bytes! 30] ; Title string. 
	artist  [bytes! 30] ; Artist string.
	album   [bytes! 30] ; Album string.
	year    [bytes!  4] ; Year string.
	comment [bytes! 30] ; Comment string.
	genre   [byte!]     ; Genre index.
]

@Oldes Oldes changed the title FEAT: preliminary support for [bytes! <size>] definitions in struct FEAT: [R/S] preliminary support for [bytes! <size>] definitions in struct Sep 12, 2017
@greggirwin
Copy link
Contributor

@PeterWAWood, and thoughts on this PR? I know @dockimbel and @qtxie need to weigh in as well, but it looks like a good idea to me, and includes tests. From the approach taken, it shouldn't affect old code that uses existing syntax.

@greggirwin
Copy link
Contributor

It also doesn't preclude further extension, from a brief evaluation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants