0
C가 작성한 이진 파일을 읽는 적절한 방법은 무엇입니까? C 헤더 파일을 가지고 있는데, 구조체가 있습니다. Go에서 수동으로 다시 쓰는 대신이 헤더 파일을 사용할 수 있습니까? 여기C가 작성한 이진 파일 읽기
/* sample.h */
#define HEADER_SIZE 2048 //* large then sizeof(header)
typedef struct {
uint8_t version;
uint8_t endian;
uint32_t createTime;
} header;
typedef struct {
uint64_t data1;
uint32_t data2;
char name[128];
} record;
는
package "main"
// #include "sample.h"
import "C"
func main() {
f, _ := os.Open("sample_file")
// read(buf, HEADER_SIZE) and print out
// use structure header to decode the buf
// while not end of file {
// read(buf, sizeof(record) and print out
// }
}
[cgo] (https://golang.org/cmd/cgo/)가 도움이 될 수 있습니다. – kichik
@kichik : OP가 이미 cgo를 사용하고 있다는 질문에서 나타납니다. – ruakh