mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00

Some checks failed
json decoder benchmark CI / json-encode-benchmark (push) Waiting to run
Graphics CI / gg-regressions (push) Waiting to run
vlib modules CI / build-module-docs (push) Waiting to run
native backend CI / native-backend-ubuntu (push) Waiting to run
native backend CI / native-backend-windows (push) Waiting to run
Shy and PV CI / v-compiles-puzzle-vibes (push) Waiting to run
Sanitized CI / sanitize-undefined-clang (push) Waiting to run
Sanitized CI / sanitize-undefined-gcc (push) Waiting to run
Sanitized CI / tests-sanitize-address-clang (push) Waiting to run
Sanitized CI / sanitize-address-msvc (push) Waiting to run
Sanitized CI / sanitize-address-gcc (push) Waiting to run
Sanitized CI / sanitize-memory-clang (push) Waiting to run
sdl CI / v-compiles-sdl-examples (push) Waiting to run
Time CI / time-linux (push) Waiting to run
Time CI / time-macos (push) Waiting to run
Time CI / time-windows (push) Waiting to run
toml CI / toml-module-pass-external-test-suites (push) Waiting to run
Tools CI / tools-linux (clang) (push) Waiting to run
Tools CI / tools-linux (gcc) (push) Waiting to run
Tools CI / tools-linux (tcc) (push) Waiting to run
Tools CI / tools-macos (clang) (push) Waiting to run
Tools CI / tools-windows (gcc) (push) Waiting to run
Tools CI / tools-windows (msvc) (push) Waiting to run
Tools CI / tools-windows (tcc) (push) Waiting to run
Tools CI / tools-docker-ubuntu-musl (push) Waiting to run
vab CI / v-compiles-os-android (push) Waiting to run
vab CI / vab-compiles-v-examples (push) Waiting to run
wasm backend CI / wasm-backend (ubuntu-22.04) (push) Waiting to run
wasm backend CI / wasm-backend (windows-2022) (push) Waiting to run
json encoder benchmark CI / json-encode-benchmark (push) Has been cancelled
50 lines
1.4 KiB
V
50 lines
1.4 KiB
V
module decoder2
|
|
|
|
// implements decoding json strings, e.g. "hello, \u2164!"
|
|
pub interface StringDecoder {
|
|
mut:
|
|
// called with raw string (minus apostrophes) e.g. 'hello, \u2164!'
|
|
from_json_string(raw_string string) !
|
|
}
|
|
|
|
// implements decoding json numbers, e.g. -1.234e23
|
|
pub interface NumberDecoder {
|
|
mut:
|
|
// called with raw string of number e.g. '-1.234e23'
|
|
from_json_number(raw_number string) !
|
|
}
|
|
|
|
// implements decoding json true/false
|
|
pub interface BooleanDecoder {
|
|
mut:
|
|
// called with converted bool
|
|
// already checked so no error needed
|
|
from_json_boolean(boolean_value bool)
|
|
}
|
|
|
|
// implements decoding json null
|
|
pub interface NullDecoder {
|
|
mut:
|
|
// only has one value
|
|
// already checked so no error needed
|
|
from_json_null()
|
|
}
|
|
|
|
// Implement once generic interfaces are more stable
|
|
|
|
// // implements decoding json arrays, e.g. ["hi", "bye", 0.9, true]
|
|
// // elements are already decoded
|
|
// pub interface ArrayDecoder[T] {
|
|
// mut:
|
|
// // called for every element in array e.g. 'hi', 'bye', '0.9', 'true'
|
|
// from_json_value(raw_value T)!
|
|
// }
|
|
|
|
// // implements decoding json object, e.g. {"name": "foo", "name": "bar", "age": 99}
|
|
// // this allows for duplicate/ordered keys to be decoded
|
|
// // elements are already decoded
|
|
// pub interface ObjectDecoder[T] {
|
|
// mut:
|
|
// // called for every key-value pair in object (minus apostrophes for keys) e.g. ('name': 'foo'), ('name': 'bar'), ('age': '99')
|
|
// from_json_pair(raw_key string, raw_value T)!
|
|
// }
|