forked from ground/ground-old
.grbc file serialization/deserialization
This commit is contained in:
48
src/serialize.h
Normal file
48
src/serialize.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef SERIALIZE_H
|
||||
#define SERIALIZE_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "types.h"
|
||||
|
||||
/*
|
||||
* Magic number and version for Ground bytecode files.
|
||||
* The magic bytes spell 'GRND'
|
||||
*/
|
||||
#define GROUND_MAGIC 0x47524E44u
|
||||
#define GROUND_VERSION 1u
|
||||
|
||||
/*
|
||||
* File header written at the start of every .grbc file.
|
||||
*/
|
||||
typedef struct GroundBytecodeHeader {
|
||||
uint32_t magic;
|
||||
uint32_t version;
|
||||
} GroundBytecodeHeader;
|
||||
|
||||
/*
|
||||
* Writes a length-prefixed UTF-8 string to (f).
|
||||
* NULL is encoded as a sentinel length (UINT32_MAX).
|
||||
* Returns true on success.
|
||||
*/
|
||||
bool serializeWriteString(FILE* f, const char* s);
|
||||
|
||||
char* serializeReadString(FILE* f);
|
||||
|
||||
|
||||
bool serializeWriteValue(FILE* f, const GroundValue* gv);
|
||||
bool serializeReadValue(FILE* f, GroundValue* out);
|
||||
|
||||
|
||||
bool serializeWriteArg(FILE* f, const GroundArg* ga);
|
||||
bool serializeReadArg(FILE* f, GroundArg* out);
|
||||
|
||||
|
||||
bool serializeWriteInstruction(FILE* f, const GroundInstruction* gi);
|
||||
bool serializeReadInstruction(FILE* f, GroundInstruction* out);
|
||||
|
||||
bool serializeProgramToFile(const char* path, const GroundProgram* prog);
|
||||
|
||||
bool deserializeProgramFromFile(const char* path, GroundProgram* out);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user