Skip to main content

Module json_string

Module json_string 

Source
Expand description

The JSON string decoder a .db JSON-brace value goes through — C’s yajl.

A .db field value has two escape regimes, and they are NOT the same function:

  • a QUOTED value (field(VAL,"a\tb")) — dbLexRoutines.c:1398 strips the quotes and runs crate::runtime::epics_string::raw_from_escaped (C dbTranslateEscapeepicsStrnRawFromEscaped);
  • a JSON-BRACE value (field(INP,{const:"a\tb"})) — dbLexRoutines.c:1398 deliberately leaves it alone (the if tests for a leading quote), because the text is handed to dbParseLinkdbJLinkInitdbJLinkParse, which feeds it to yajl; yajl’s lexer flags a string with escapes and yajl_parser.c:273-281 decodes it through yajl_string_decode (yajl_encode.c:136-215) before the jlif string callback ever sees it (lnkConst.c:199).

The port carried the brace text verbatim all the way into the record, so every JSON link carrying an escaped string — {const:"…"} seeds, {pva:{pv:"…"}} targets — reached the record with its backslashes intact.

Measured, softIoc 7.0.10 (linux-x86_64), dbgf (which re-escapes for display, so a stored backslash prints DOUBLED):

record(stringin,"J1"){field(DTYP,"Soft Channel") field(INP,{const:"a\tb"})}
    dbgf J1.VAL -> "a\tb"    i.e. stored a, TAB, b
record(stringin,"J2"){field(DTYP,"Soft Channel") field(INP,{const:"x\\ny"})}
    dbgf J2.VAL -> "x\\ny"   i.e. stored x, BACKSLASH, n, y

(caget/caget-rs are NOT oracles here: both print a DBF_STRING through epicsStrnEscapedFromRawtool_lib.c:135, cli.rs:834 — so a stored TAB comes back on screen as \t and reads exactly like an untranslated escape.)

Functions§

decode_json_string
C yajl_string_decode (yajl_encode.c:136-215): decode the CONTENT of a JSON string (no surrounding quotes).
decode_json_string_token
A JSON string TOKEN — quotes included — decoded. None when tok is not a quoted string (a number, true, an object, …): C’s jlif string callback is simply not the one yajl calls for those.