OxL Справочник OxL
РусскийEnglish

method Encoder.isJson

Whether the format is JSON (codecs may then write a different representation: @codec(json: C)).

Example:

oxl✓ проверяется в CI
use std.ser { Codec, Encoder, Decoder, Schema, encode, decode, hex, EncodeError, DecodeError }

data Both {}

impl Codec<i64> for Both {
  static fn encode(x: &i64, w: &var Encoder) -> () | EncodeError {
    if w.isJson() { w.writeStr("n{x}") } else { w.writeI64(x) }
  }
  static fn decode(r: &var Decoder) -> i64 | DecodeError { r.readI64() }
  static fn schema() -> Schema => Schema.of("int64")
}

fn main() io {
  print("ok")
}
Вывод
ok
fn isJson() -> bool

С версии. 1.0.0-beta

Возвращает

bool

Эффекты

не объявлены (чистая, пока тело не говорит иное)

Определено в: std/ser/ser.oxl:450

См. также