1
0
forked from ground/ground-old
This repository has been archived on 2026-03-16. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
ground_old_fork/src/serialize.h

49 lines
1.1 KiB
C

#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