473,763 Members | 3,855 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Suggested format for data encapsulation

Hello,

I have a fairly complex project with server-side written in C# (.NET),
and client-side heavily relying on the presence on
JavaScript-compatible scripting engine. One of the features thie
project utilizes is "virtual POST", ie, client side submits the data
to the server side, using Microsoft.XMLHT TP ActiveX Object (in MSIE),
or XMLHttpRequest class in Mozilla, and when the server returns reply,
processes it in client side to run some JavaScript and manipulate with
DOM.
The thing is, I am looking for decent, not-too-verbose data
serialization encoding that would allow me to send JavaScript-type
data to the server and back. With JavaScript-type data I mean value
that could be described as one of the following:
0) null
1) numeric value
2) string value in quotes
3) boolean value: true/false
4) date value: new Date(x, y, z)
5) array: [value, value, ...]
6) object: {value:value, value:value, ...}
Here is example of the tata that I want to be able to xfer to and from
the server:
[1, "abc", true, {a:1, b:[10,11,12, new Date(x, y, z)], c:{x:"foo",
y:"bar"}}]

Until today , I used JSON (http://www.crockford.com/JSON/index.html)
notation, cause I find it short and to the point. I have wrote my own
JavaScript code for encoding and decoding the data to and from the
JSON. However, I have stumbled upon the situation that for large data
blocks the client-side scripting engine is too weak to parse it in
reasonable time, and I am forced to use another encoding. So, now I am
thinking on XML encoding. The example above could be encoded like
this:

<value type="array">
<value type="num" value="1"/>
<value type="str" value="abc"/>
<value type="bool" vaue="true"/>
<value type="object">
<value key="a" type="num" value="1"/>
<value key="b" type="array">
<value type="num" value="10"/>
<value type="num" value="11"/>
<value type="num" value="12"/>
<value type="date" value="x y z"/>
</value>
<value key="c" type="object">
<value key="x" type="str" value="foo"/>
<value key="y" type="str" value="bar"/>
</value>
</value>
</value>

Which, of course, is much more verbose, but still the shortest way I
can think of to describe the JavaScript data structures in XML. Plus,
I could do speedy parsing on the client-side using built-in XML
parsers (vs present JSON parse that is driven by series of Regex
searches that make it slow).

So, my question is, whether there is already some running initiative
on this matter, and perhaps I need not to reinvent the wheel, and
JavaScript encoding/decoding code for this serialization format is
available?

Regards,
Pavils Jurjans
Jul 23 '05 #1
2 1694
Pavils Jurjans wrote:

Hi,
Until today , I used JSON (http://www.crockford.com/JSON/index.html)
notation, cause I find it short and to the point. I have wrote my own
JavaScript code for encoding and decoding the data to and from the
JSON. However, I have stumbled upon the situation that for large data
blocks the client-side scripting engine is too weak to parse it in
reasonable time, and I am forced to use another encoding. Plus,
I could do speedy parsing on the client-side using built-in XML
parsers (vs present JSON parse that is driven by series of Regex
searches that make it slow).


JS Regexp engine is NFA-based, so the way you've scripted your regular
expressions may have a huge impact - regexps optimisation would be a
good lead, using standard stuff such as anchors, non-greedy operators...

However as you describe it you just seem to need a tree (as would an XML
parser would give you) - so why don't you directly eval the JSON
structure, as recommended by the author?

<URL:http://www.crockford.c om/JSON/js.html>
As for your original question, I'm aware of no tool like the one you're
searching, but OTOH I've never needed any - I'll leave to others the
Ultimate Tool Recommendation:-)
Cheers,
Yep.
Jul 23 '05 #2
Hi Yann-Erwan,
JS Regexp engine is NFA-based, so the way you've scripted your regular expressions may have a huge impact - regexps optimisation would be a
good lead, using standard stuff such as anchors, non-greedy operators...

Ok, I'll try do check this... yet I'm sort of unsure if that's the way
to go. The processing of large data block still will be quite slow. Why
should the user suffer?
However as you describe it you just seem to need a tree (as would an XML parser would give you) - so why don't you directly eval the JSON
structure, as recommended by the author?


Because the eval is much more powerful. In case of bad formatting of
illegal features I want to throw error at the client side. eval could
do evil things - run functions, override global variables, etc. I want
to control the parsing, because it's more secure.

I came to concluction that I could shorten the XML format even more:

<array>
<num value="1"/>
<str value="abc"/>
<bool value="true"/>
<object>
<num key="a" value="1"/>
<array key="b">
<num value="10"/>
<num value="11"/>
<num value="12"/>
<time value="25-02-2005 13:11"/>
</array>
<object key="c">
<str key="x" value="foo"/>
<str key="y" value="bar"/>
</object>
</object>
</array>

If no other stardard will be suggested from the group until the end of
february, I will go on and implement this.

Regards,

Pavils

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4114
by: blueblueblue2005 | last post by:
here is a friend function of Class Array, which has two private data member: int size, int *ptr // Array's public member function to return size int getSize() const { return size; } friend istream &operator>>(istream &in, Array &a) { for(int i=0; i<a.size; i++) // do something
12
2093
by: Alex Hunsley | last post by:
There's no really specific questions in this post, but I'm looking for people's thought on the issues within... The two main versions I've encountered for data pseudo-hiding (encapsulation) in python are: method 1: _X - (single underscore) - just cosmetic, a convention to let someone
2
1441
by: Neo | last post by:
I was written this code; in VS2k5 class Program { private: int a;
63
2681
by: time.swift | last post by:
Coming from a C++ / C# background, the lack of emphasis on private data seems weird to me. I've often found wrapping private data useful to prevent bugs and enforce error checking.. It appears to me (perhaps wrongly) that Python prefers to leave class data public. What is the logic behind that choice? Thanks any insight.
32
4225
by: bluejack | last post by:
Ahoy: For as long as I've been using C, I've vacillated on the optimal degree of encapsulation in my designs. At a minimum, I aggregate data and code that operate on that data into classlike files; but now and then I go on an opaque type joyride, and create minimalist header files that define very clean interfaces. The problem with that is that it prevents some optimizations:
11
5655
by: sofeng | last post by:
I'm not sure if "data hiding" is the correct term, but I'm trying to emulate this object-oriented technique. I know C++ probably provides much more than my example, but I'd just like some feedback to find out if I've done anything wrong. Also, I am working on this for an embedded environment, so if there are great inefficiencies with this code, I'd like to know that also. I realize there is overhead with using an "accessor" function. ...
1
14223
by: subramanian100in | last post by:
I am a beginner in C++. I come across the terms data abstraction and encapsulation in C++. I am unable to understand the definitions. Kindly explain these terms with a simple example in C++ Thanks V.Subramanian
2
7640
by: subramanian100in | last post by:
Is my following understanding correct ? Data abstraction means providing the interface - that is, the set of functions that can be called by the user of a class. Information hiding means mentioning the class members(functions, typedefs, data) under the access control labels : public, protected, private. Encapsulation means providing the implementation of class member
162
10293
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you prefix them with 2 underscores, but I hate prefixing my vars, I'd rather add a keyword before it. Python advertises himself as a full OOP language, but why does it miss one of the basic principles of OOP? Will it ever be added to python?
0
9566
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9389
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10003
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9943
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9828
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5271
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5410
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3529
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.