|
I assumed you have access to std::string find()
Not so much complexity IMO...
"If we don't change direction, we'll end up where we're going"
|
|
|
|
|
that only works for in memory strings.
To err is human. Fortune favors the monsters.
|
|
|
|
|
And for standard C there is of course always <string.h> with strstr() that I assume you know
"If we don't change direction, we'll end up where we're going"
|
|
|
|
|
strstr only works for in memory strings, not streams.
To err is human. Fortune favors the monsters.
|
|
|
|
|
One of the nice things about embedded is that generally, if you have adequate implementation, unit testing and system testing, you can safely assume your input will not be corrupt. I.e. embedded implementations can be fully and specifically bounded and 'gated' in such a way as to avoid input errors - frames can be error checked, etc, etc. Moving data errors into places they can be easily managed is a key piece of making 'engines' more efficient.
The exact same paradigm is the way a car is built - or better example - a boat. You would never build an engine for a boat to be able to take water in the fuel. You 'move' the error handling (water in the fuel) to an input qualifying filter. Fuel filters for boats and cars are very different beasts, the engines are (fundamentally) the same.
|
|
|
|
|
honey the codewitch wrote: 3 languages
Regex
C++
C#
To "parse" a fourth, a JSON subset
This brings to mind the children's song about the old lady who swallowed a fly.
The two last verses are:
I know an old lady
Who swallowed a cow.
I don't know how
She swallowed a cow
She swallowed the cow to catch the dog
What a hog to swallow a dog!
She swallowed the dog to catch the cat
Fancy that! To swallow a cat!
She swallowed the cat to catch the bird
How absurd, to swallowed a bird!
She swallowed the bird to catch the spider
That wriggled and tickled inside her.
She swallowed the spider to catch the fly.
I don't know why she swallowed a fly.
Perhaps she'll die...
I know an old lady who swallowed a horse!
She's dead, of course .
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
Why not parsing JSON in C# directly? That's a dependency on .NET's standard runtime library which ain't too bad.
|
|
|
|
|
Because first it would mean upgrading the SRAM on my device to something more than 512kB
Then it would involve upgrading the processor to something in the GHz range
And heck, it would involve adding a PC in there somewhere to actually run .NET.
This is not a .NET device[^]
To err is human. Fortune favors the monsters.
|
|
|
|
|
Things are getting insteresting! What and how do you compile C# down to? Can I imagine what you're doing to be similar to what the Unity developers are doing (compiling C# to C++ which then gets compiled to native code)?
|
|
|
|
|
I'm just basically using C# to generate an array for my C++ code to traverse. The C# code is a console application.
I feed it a regular expression on the command line and it produces a small amount of C++ code to declare an array as its output - for example:
int16_t dfa_table[] = {
-1, 1, 6, 1, 34, 34, -1, 1, 12, 1, 117, 117, -1, 1, 18,
1, 110, 110, -1, 1, 24, 1, 105, 105, -1, 1, 30, 1, 120, 120,
-1, 1, 36, 1, 116, 116, -1, 1, 42, 1, 105, 105, -1, 1, 48,
1, 109, 109, -1, 1, 54, 1, 101, 101, -1, 1, 60, 1, 34, 34,
-1, 1, 66, 1, 58, 58, 0, 0
};
That's a DFA table. What it is is a state machine encoded into an array. I have C++ code that can walk it in order to run the regular expression. The walking code is easy and efficient. Generating the array is not easy.
That C# console application uses a regular expression engine I wrote (in C#) in order to generate that C++ array. The code to run the regular expression is simple and is in C++:
bool match(const int16_t* dfa, int16_t(read_cb)(void*), void* cb_state = nullptr) {
int tlen;
int tto;
int prlen;
int pmin;
int pmax;
int i;
int j;
int ch;
int state = 0;
bool done;
bool found = false;
int acc = -1;
ch = read_cb(cb_state);
while (ch != -1) {
acc = -1;
done = false;
while (!done) {
start_dfa:
done = true;
acc = dfa[state++];
tlen = dfa[state++];
for (i = 0; i < tlen; ++i) {
tto = dfa[state++];
prlen = dfa[state++];
for (j = 0; j < prlen; ++j) {
pmin = dfa[state++];
pmax = dfa[state++];
if (ch < pmin) break;
if (ch <= pmax) {
found = true;
ch = read_cb(cb_state);
state = tto;
done = false;
goto start_dfa;
}
}
}
}
if (acc != -1) {
return found;
}
ch = read_cb(cb_state);
state = 0;
}
return false;
}
To err is human. Fortune favors the monsters.
|
|
|
|
|
Ah, I get it. Thank you for the thorough explanation
|
|
|
|
|
No problem. I don't target .NET these days, as I spend most of time with tiny little gadgets. To me .NET is a means to an end. If I can use it to offload some of the heavy lifting my code would otherwise have to do I'll do that, of course. Otherwise I haven't really used it recently. I do have a lot of code I've written in C#, and used to use it professionally - sometimes I still will every once in awhile, but it's not my bread and butter anymore.
The regular expression thing is a great example of being able to use it to offload work though - where an actual regular expression engine on the device would take up precious RAM and flash space, I was able to "outsource it" to an external C# app I only need to run once.
To err is human. Fortune favors the monsters.
|
|
|
|
|
I'd go as far as to claim for everything to be means to and end. Programming something embedded in C++, it still is means to an end :p
|
|
|
|
|
Ha! Okay that's fair. But in this case, I mean I'll use it to facilitate my IoT development, rather than use it to make applications that are meant to be used standalone or even libraries from C#.
To err is human. Fortune favors the monsters.
|
|
|
|
|
sounds awesome.
when reading the comments and when start talking about tens of kilobytes, I know way out of my depth. Trying to figure out library and runtime differences of Regex/JSON and not getting anywhre Ill just fallback to Regex being many times older and many works of optimising and minimising.
JSON format been great for the balance of human readability and reduced redundancy of XML, but where computers matter, bits is all that they care about.
|
|
|
|
|
Their latest innovation - paper money!
Offline Cash
Including this bafflegab: Quote: The Bitcoin Note uses a multisig that combines a local encrypted key with a private key that you generate. The stored Bitcoin is only claimable when the holder cuts the note.
If you receive a note that you want to keep in cold storage, you can re-key it from entropy you generate. After expiration only the locally stored user generated private key can access the funds.
TTFN - Kent
|
|
|
|
|
I suppose that this is their way of saying "look we have notes too... we do are a normal currency not just a speculative game"
And I wonder how many people is going to be blocked out of their funds once they start to doing that.
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Simple to understand, similar to Las Vegas casinos.
Enter, donate, go home broke.
>64
Some days the dragon wins. Suck it up.
|
|
|
|
|
Every time I think we've GOTTEN to peak Dunning-Krugerrand they have to go and do something else.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
|
|
|
|
|
Even Sprint's robo-voice says "got" instead of "received." I guess they have to dumb it down for the masses.
|
|
|
|
|
Yes, as is invite (invitation), info (information), wanna (want to) ... the list goes on.
|
|
|
|
|
And the correct spelling of "through" is doomed as well.
|
|
|
|
|
Not to mention Dutch sayings like: "Make that the cat wise"
|
|
|
|
|
On engineering drawings, through is spelt thru or even thro 🤷🏻
modified 6-Sep-22 21:01pm.
|
|
|
|
|
Don't even get me started on could/would/should of. I've even seen them in places that should definitely know better.
Before vituperating about another one, I thought I'd check if it's now accepted. Sure enough[^], ffs. I first heard it trotted out by a native French speaker and wondered if the plan might actually be to get some people pregnant.
|
|
|
|
|