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

method Decoder.isJson

Whether the input is JSON.

Example:

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

data Flexible {}

impl Codec<i64> for Flexible {
  static fn encode(x: &i64, w: &var Encoder) -> () | EncodeError { w.writeI64(x) }
  static fn decode(r: &var Decoder) -> i64 | DecodeError {
    if r.isJson() {
      match r.readStr() {
        str s => match s.parse<i64>() {
          i64 n => n
          ParseError _ => fail DecodeError.Invalid(msg: "not a number")
        }
        DecodeError e => fail e
      }
    } else {
      r.readI64()
    }
  }
  static fn schema() -> Schema => Schema.of("int64")
}
fn isJson() -> bool

С версии. 1.0.0-beta

Возвращает

bool

Эффекты

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

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

См. также