The MASM Forum

General => The Campus => Topic started by: iguananed on June 20, 2018, 06:43:43 AM

Title: JSON Parser
Post by: iguananed on June 20, 2018, 06:43:43 AM
Just started my dabbling in MASM32 trying to determine if I will be able to develop my next application wioth it.

I am looking at making a High speed middle-ware application which will interface two systems using REST.

I have not found any examples of using MASM32 to parse JSON.

any help you be appreciated.
Title: Re: JSON Parser
Post by: Raistlin on June 20, 2018, 07:03:25 AM
Really hard to believe you haven't seen any.
Assembly using SSE is all the rage for JSON.
see: https://amp-reddit-com.cdn.ampproject.org/v/s/amp.reddit.com/r/programming/comments/3pojrz/the_fastest_json_parser_in_the_world/?amp_js_v=a1&amp_gsa=1&usqp=mq331AQCCAE%3D#referrer=
Title: Re: JSON Parser
Post by: jj2007 on June 20, 2018, 08:35:13 AM
Interesting link, Raistlin. Some clicks further is a SOF article on the SSE4.2 string functions (https://stackoverflow.com/questions/46762813/how-much-faster-are-sse4-2-string-instructions-than-sse2-for-memcmp). like pcmpistrm and pcmpestrm, with some surprises.
Title: Re: JSON Parser
Post by: iguananed on June 21, 2018, 01:38:05 AM
Quote from: Raistlin on June 20, 2018, 07:03:25 AM
Really hard to believe you haven't seen any.
Assembly using SSE is all the rage for JSON.
see: https://amp-reddit-com.cdn.ampproject.org/v/s/amp.reddit.com/r/programming/comments/3pojrz/the_fastest_json_parser_in_the_world/?amp_js_v=a1&amp_gsa=1&usqp=mq331AQCCAE%3D#referrer=

Sorry I should have been a bit more specific. I have not seen any Source code examples or libraries.

I am looking for something like this the following but for MASM32,  https://2ton.com.au/library_as_html/json.inc.html

Title: Re: JSON Parser
Post by: Raistlin on June 21, 2018, 02:44:25 AM
Right, so that's a 64-bit library that does what you want.(link)
What's the problem then ? Not optimized ? Not enough SSE ?
AVX interesting ? The person that wrote it is not a native ASM
personage and missed a crap load of obvious cool stuff?

Now I (we, sorry guys I am being presumptive) need to know, do you have ASM expierence and want to write this? Or are you
waiting (hoping) someone has or will take up
the project ? This is sort of what it boils down
to. No effort on your part = no gain. There are
some serious weirdo SSE\AVX nuts (ppl) on
this forum. But why would they not just write the
commercial middleware themselves or consider
helping you without real effort (not copy & paste (c)).

Please understand the situation you are describing
Title: Re: JSON Parser
Post by: iguananed on June 21, 2018, 06:45:24 AM
I have very little(none)  ASM experience. Just did not want to re invent the wheel. I figured it was something that might have already been done.
Title: Re: JSON Parser
Post by: Raistlin on June 21, 2018, 07:10:38 AM
Really well done young padewan. Seriously = No, that 64-bit lib looks suspect. I have had the privilege of seeing god-like SSE
and 64-bit code in my lifetime. Where? Right here on the forum.

The thing is, no one here will write code for you, ever. The end. They will however painstakingly help you with your code....
ASM is the BEST, but you probably know that already. The
fastest & smallest & sexy-ist code & most difficult to unlearn in the world (probably universe) = assembly. Absolute perfection
is always around the corner. Believe me, I am still hunting

BTW: We reinvent the wheel here on a daily basis. The wheels produced here, are from time to time the
subject of  international peer reviewed research papers,.
Title: Re: JSON Parser
Post by: 2ton on June 21, 2018, 07:58:02 AM
Quote from: Raistlin on June 21, 2018, 07:10:38 AM
Seriously = No, that 64-bit lib looks suspect.
Author of said lib chiming in, curious as to why you think it is suspect. (As mentioned elsewhere, it is general purpose and <= SSE2 quite intentionally, and GPL).

Cheers
Title: Re: JSON Parser
Post by: Raistlin on June 21, 2018, 08:19:27 AM
@2ton: Doubtfull. Copy and paste original source & we might
talk.(PM if you want). What  has GPL have to do with anything around the conversation. Doesn't make for better code, or is that
an invite? The belief is there is sub optimum SSE instruction
usage blatantly evident in the perused (prompently copyrighted) library, that no-one seemingly knew about. Until posted here that is.... suspect

My opinion is mine, asked for and answered. If you disagree,
so be it.. Find someone else to help.....
Title: Re: JSON Parser
Post by: jj2007 on June 21, 2018, 08:48:14 AM
Quote from: Raistlin on June 21, 2018, 08:19:27 AM
@2ton: Doubtfull. Copy and paste original source

It seems this page (https://2ton.com.au/library_as_html/json.inc.html) is indeed the original source.
Title: Re: JSON Parser
Post by: 2ton on June 21, 2018, 08:48:44 AM
Doubtful of what?

An example of using my library to deal with JSON:include 'ht/ht_defaults.inc'
include 'ht/ht.inc'

public _start
_start:
; initialise the library
call ht$init
; simple case: create a new named json object
mov rdi, .oname
call json$newobject
mov rbx, rax
mov rdi, rax
call json$tostring
mov r12, rax
mov rdi, rax
call string$to_stdoutln
mov rdi, r12
call heap$free
mov rdi, rbx
call json$destroy

; next case: parse json
mov rdi, .jtext
xor esi, esi
call json$parse_object
; turn that back into a string
mov rbx, rax
mov rdi, rax
call json$tostring
mov r12, rax
mov rdi, rax
call string$to_stdoutln
mov rdi, r12
call heap$free
mov rdi, rbx
call json$destroy

; bailout
mov eax, syscall_exit
xor edi, edi
syscall
cleartext .oname, 'ObjectName'
cleartext .jtext, '{"varone":true,"vartwo":"string","varthree":1.553,"varfour":[1,2,3,4,5,6,7,8,9],"varfive":{"subvarone":"Heya"}}'

include 'ht/ht_data.inc'


When run, it outputs "ObjectName":{}
{"varone":true,"vartwo":"string","varthree":1.553,"varfour":[1,2,3,4,5,6,7,8,9],"varfive":{"subvarone":"Heya"}}
Title: Re: JSON Parser
Post by: fearless on June 21, 2018, 10:35:25 AM
Could just use an existing json library

http://www.digip.org/jansson/ (http://www.digip.org/jansson/)
or
https://github.com/DaveGamble/cJSON (https://github.com/DaveGamble/cJSON)
I have some precompiled libs for those in x86 and x64 with masm style includes:

- https://github.com/mrfearless/libraries/tree/master/Jansson
- https://github.com/mrfearless/libraries/tree/master/cJSON
Title: Re: JSON Parser
Post by: fearless on June 09, 2019, 02:44:43 AM
I've updated the cjson (https://github.com/DaveGamble/cJSON (https://github.com/DaveGamble/cJSON)) (previously libcjson v1.6.0) compiled static libraries to v1.7.12: https://github.com/mrfearless/libraries/tree/master/cJSON (https://github.com/mrfearless/libraries/tree/master/cJSON)

Also I've moved the cjsontree x86 demo program to it's own repository: https://github.com/mrfearless/cjsontree (https://github.com/mrfearless/cjsontree) (todo: x64 version)
Fixed a few bugs, and got it to output text based json for export and/or save using the cJSON_PrintBuffered api call. Previously I was trying to do this manually myself and it proved to be troublesome and overly complicated - for some reason I didn't see or know about the cJSON_Print api's.
Title: Re: JSON Parser
Post by: 2B||!2B on June 11, 2019, 12:18:42 PM
Nice work fearless.
Problem is i can not compile your demo.

Writing 24:1, lang:0x409, size 750.Res/cjsontreeRes.rc (50): error RC2176 : old DIB in Images/j.ico; pass it through SDKPAINT
Title: Re: JSON Parser
Post by: fearless on June 11, 2019, 07:25:51 PM
Thats odd. What version is your resource compiler?
I'm using: Microsoft (R) Windows (R) Resource Compiler Version 6.3.9600.17336
To test, I downloaded the zip of the repository and extracted to a new folder, opened the RadASM project and Make->Compile RC and it seemed to work ok.
The version of RC is the only thing that I can think of that might be the issue
Title: Re: JSON Parser
Post by: hutch-- on June 11, 2019, 09:49:55 PM
Why not just replace the icon ?
Title: Re: JSON Parser
Post by: 2B||!2B on June 28, 2019, 08:29:07 PM
fearless thanks. Sorry for the late reply

I just use the default RC that comes with the MASM32.

Microsoft (R) Windows (R) Resource Compiler, Version 5.00.1823.1 - Build 1823
Copyright (C) Microsoft Corp. 1985-1998. All rights reserved.


But i changed to use VC++ 2008 resource compiler and it compiled successfully. Very good example  :thup:

hutch--
Sorry, i have already changed icon and it did not work. I think because icon is new and big one ~360kb.
Later i learned that smaller icons with basic colors compile fine with MASM32 default resource compiler.
Title: Re: JSON Parser
Post by: hutch-- on June 29, 2019, 10:13:20 PM
Try the LoadResource API, it handles larger images.
Title: Re: JSON Parser
Post by: HSE on August 03, 2021, 03:19:24 AM
Hi Fearless!

Playing a little with JSON I noted a little problem in cjsontree.

In principle is valid :{
  "obj1":{"value1":"x", "value2":"y"},
  "obj1":{"value1":"x2", "value2":"y2"},
  "obj1":{"value1":"x3", "value2":"y3"}
}

wich apparently is better to write:{
  "obj1":[
  { etc},
  { etc},
  { etc}
]
}


cjsontree correctly take as valid first format, but there is a problem in the tree:ffear1.json
|- value1:x
|- value2:y
+ obj1
+ obj1


Regards, HSE