MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / emit_js

Function emit_js

scripts/generate-sdk.py:79–229  ·  view source on GitHub ↗
(commands)

Source from the content-addressed store, hash-verified

77
78
79def emit_js(commands):
80 lines = []
81 lines.append("// AUTO-GENERATED by scripts/generate-sdk.py. Do not edit by hand.")
82 lines.append(
83 "// Natural wrappers over apiCall(method, params). Refresh with sanitize-commit."
84 )
85 lines.append("")
86 lines.append("var SerialStudio = {")
87 lines.append(" Base64: 0,")
88 lines.append(" Hex: 1,")
89 lines.append(" Text: 2,")
90 lines.append("")
91 lines.append(
92 " _b64: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',"
93 )
94 lines.append("")
95 lines.append(" _toBase64: function(bytes) {")
96 lines.append(" var out = '', n = bytes.length;")
97 lines.append(" for (var i = 0; i < n; i += 3) {")
98 lines.append(" var b1 = bytes[i] & 0xff;")
99 lines.append(" var has2 = i + 1 < n, has3 = i + 2 < n;")
100 lines.append(" var b2 = has2 ? (bytes[i + 1] & 0xff) : 0;")
101 lines.append(" var b3 = has3 ? (bytes[i + 2] & 0xff) : 0;")
102 lines.append(" var t = (b1 << 16) | (b2 << 8) | b3;")
103 lines.append(" out += this._b64.charAt((t >> 18) & 0x3f);")
104 lines.append(" out += this._b64.charAt((t >> 12) & 0x3f);")
105 lines.append(" out += has2 ? this._b64.charAt((t >> 6) & 0x3f) : '=';")
106 lines.append(" out += has3 ? this._b64.charAt(t & 0x3f) : '=';")
107 lines.append(" }")
108 lines.append(" return out;")
109 lines.append(" },")
110 lines.append("")
111 lines.append(" _encode: function(value, encoding) {")
112 lines.append(" if (encoding === SerialStudio.Hex) {")
113 lines.append(
114 " var hex = String(value).replace(/[^0-9a-fA-F]/g, ''), bytes = [];"
115 )
116 lines.append(" for (var i = 0; i < hex.length; i += 2)")
117 lines.append(" bytes.push(parseInt(hex.substr(i, 2), 16));")
118 lines.append(" return SerialStudio._toBase64(bytes);")
119 lines.append(" }")
120 lines.append(" if (encoding === SerialStudio.Text) {")
121 lines.append(" var s = String(value), out = [];")
122 lines.append(" for (var j = 0; j < s.length; ++j)")
123 lines.append(" out.push(s.charCodeAt(j) & 0xff);")
124 lines.append(" return SerialStudio._toBase64(out);")
125 lines.append(" }")
126 lines.append(" return value; // already base64")
127 lines.append(" }")
128 lines.append("};")
129 lines.append("")
130 lines.append(
131 "// Core gateway. The host installs the bridge object as __ss_bridge; every"
132 )
133 lines.append(
134 "// wrapper below routes through apiCall. delay() exists only where the host"
135 )
136 lines.append("// bridge provides it (the control script's worker thread).")

Callers 1

mainFunction · 0.85

Calls 8

read_preludeFunction · 0.85
ordered_paramsFunction · 0.85
js_identFunction · 0.85
is_byte_paramFunction · 0.85
setFunction · 0.50
appendMethod · 0.45
addMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected