Files
ziran/std/json_go.zi
T
waozi 38710d1fd9 Mark std foreign procedures that only read their strings #reads
StringRaw, BytesNil, the ed25519 seed, sign and verify calls, json
ValidRaw, net ParseRaw and hmac Sum256 only read their string and byte
arguments during the call, so Text passed to them is freed.
2026-11-06 17:28:46 -03:00

43 lines
1.5 KiB
Ziran

// Go JSON serialization keeps native error values, field tags and byte storage.
#import "go_types"
io :: #import "io_go";
go_json :: #system_library "go:encoding/json";
Encoder :: #type #foreign go_json "Encoder";
Decoder :: #type #foreign go_json "Decoder";
JSONResult :: struct {
value: []u8
error: Error
}
#scope_file
MarshalRaw :: (value: Any) -> JSONResult #go_results #foreign go_json "Marshal";
UnmarshalRaw :: (data: []u8, value: Any) -> Error #foreign go_json "Unmarshal";
ValidRaw :: (data: []u8) -> bool #reads #foreign go_json "Valid";
NewEncoderRaw :: (writer: io.Writer) -> *Encoder #foreign go_json "NewEncoder";
EncodeRaw :: (encoder: *Encoder, value: Any) -> Error #foreign go_json "(*Encoder).Encode";
NewDecoderRaw :: (reader: io.Reader) -> *Decoder #foreign go_json "NewDecoder";
DecodeRaw :: (decoder: *Decoder, value: Any) -> Error #foreign go_json "(*Decoder).Decode";
#scope_export
Marshal :: (value: Any) -> JSONResult {
return MarshalRaw(value)
}
Unmarshal :: (data: []u8, value: Any) -> Error {
return UnmarshalRaw(data, value)
}
Valid :: (data: []u8) -> bool {
return ValidRaw(data)
}
NewEncoder :: (writer: io.Writer) -> *Encoder {
return NewEncoderRaw(writer)
}
Encode :: (encoder: *Encoder, value: Any) -> Error {
return EncodeRaw(encoder, value)
}
NewDecoder :: (reader: io.Reader) -> *Decoder {
return NewDecoderRaw(reader)
}
Decode :: (decoder: *Decoder, value: Any) -> Error {
return DecodeRaw(decoder, value)
}