Skip to content
Snippets Groups Projects
Select Git revision
  • 93d4e186c2f45ba4f16cbe1dd107545b606dde89
  • master default protected
  • v3.1-stable
  • v2.4-stable
  • v3.0-stable
  • esp32
  • v2.3-stable
  • v2.2-stable
  • v2.1-stable
  • v1.7-stable
  • v2.0-stable
  • v1.6-stable
  • v1.5-stable
  • coverity_scan
  • v3.1.0
  • v3.0.1
  • v3.0.0
  • v2.4.2
  • v2.4.1
  • v2.4.0
  • v2.3.0
  • v2.2.2
  • v2.2.1
  • v2.2.0
  • v2.1.1
  • v2.1.0
  • v2.0.3
  • v1.7.9
  • v2.1-pre3
  • v2.0.2
  • v2.0.1
  • v1.7.8
  • v2.0.0
  • v1.7.7
34 results

openssl-server.c

Blame
  • add.ts 1.65 KiB
    import { DecodeFn, EncodeFn } from "../../types";
    import * as util from "../util";
    import {
      AddLookupCreateObject,
      AddLookupCreateParamSetting,
    } from "../../types";
    import { parseSetArgs } from "../../util";
    
    const decode: DecodeFn = (msg) => {
      const paths: string[] | undefined = util.searchAll(msg, "instantiatedPath");
      if (paths && paths.length === 1) return [paths[0]];
      return [paths];
    };
    
    const isObj = (v) =>
      typeof v === "object" && v.required !== undefined && v.value !== undefined;
    
    const makePair = (value): [string, any, boolean][] =>
      value
        ? Object.entries(value as any[]).map(([k, v]) =>
            isObj(v)
              ? [k, v.value.toString(), "required" in v && Boolean(v.required)]
              : [k, v.toString(), true]
          )
        : [];
    
    const encode: EncodeFn = ({ value, path }) => {
      const [paths, values] = parseSetArgs(value, path);
      const allowPartial =
        (values && values.some((it) => it.allowPartial)) || false;
    
      const createObjs = paths.map((path, i) => ({
        lookup: "Add.CreateObject" as AddLookupCreateObject,
        objPath: path,
        paramSettings: makePair(values[i])
          .filter(([k]) => k !== "allowPartial")
          .map(([param, value, required]) => ({
            lookup: "Add.CreateParamSetting" as AddLookupCreateParamSetting,
            param,
            value,
            required,
          })),
      }));
    
      return {
        lookup: "Msg",
        header: {
          lookup: "Header",
          msgId: util.uniq("ADD@"),
          msgType: "ADD",
        },
        body: {
          lookup: "Body",
          request: {
            lookup: "Request",
            add: {
              allowPartial,
              createObjs,
            },
          },
        },
      };
    };
    
    export default {
      decode,
      encode,
    };