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

GO binding struct for a self referencing struct #4

Closed
vposham opened this issue Jan 20, 2020 · 3 comments
Closed

GO binding struct for a self referencing struct #4

vposham opened this issue Jan 20, 2020 · 3 comments

Comments

@vposham
Copy link

vposham commented Jan 20, 2020

Hi,

Any ideas on how to write a golang equivalent struct for self referencing struct something like this -

typedef struct WRITER {
int version;
int (WriteBlock)(struct WRITER thisPtr,
const void* dataBufferPtr,
unsigned long bufferSize);
} WRITER;

Thanks.

@draffensperger
Copy link
Owner

Given that cgo allows you to reference C types via something like C.WRITER, in this case would it make sense to just reference the C types directly? Then maybe you could have a Go wrapper for a higher level concept in your program such as the thing that does the writing using the underlying struct.

@vposham
Copy link
Author

vposham commented Jan 21, 2020

Disclaimer : Im a C noob who just came to know that - there is something like self referencing structs.

I tried directly referencing C struct like C.WRITER, but the WriteBlock method implementation is required to use the object in a meaningful way.

To give more context - Im trying to write a Go struct wrapper for FPDF_FILEWRITE_ struct to use in FPDF_SaveAsCopy function.

https://pdfium.googlesource.com/pdfium/+/refs/heads/master/public/fpdf_save.h

@vposham
Copy link
Author

vposham commented Jan 21, 2020

Digging further, I came to know that something like this needs to be implemented in GO.

@vposham vposham closed this as completed May 2, 2020
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

No branches or pull requests

2 participants