Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
➜ MUSHclient
➜ Lua
➜ Compression and decompression
Compression and decompression
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Nick Gammon
Australia (23,072 posts) Bio
Forum Administrator |
Date
| Thu 09 Dec 2004 03:25 AM (UTC) |
Message
| Introduction
Lua strings have the useful attribute that they can contain any character, including the 'null' character (hex 00) which is often used in C to delimit strings.
With this in mind, version 3.57 of MUSHclient offers compression and decompression for Lua scripting. This is based on the zLib library which is already incorporated into MUSHclient for use in MCCP decompression.
Compress
utils.compress (s [, method] )
Compresses string s and returns the compressed form. Note that it may contain nulls (bytes with a zero value).
The optional argument 'method' indicates the level of compression you want.
- 0 = no compression
- 1 = best speed
....
- 9 = best compression
The default, if omitted, is 6.
Decompression
utils.decompress (s)
Decompresses string s and returns the decompressed form. Raises an error if decompression cannot be done (eg. bad compressed data).
These two functions should be complementary, so that this should always be true:
x = "some string" -- for any (string) data whatsoever
y = utils.decompress (utils.compress (x)) --> y should be same as x
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Poromenos
Greece (1,037 posts) Bio
|
Date
| Reply #1 on Thu 09 Dec 2004 10:54 PM (UTC) |
Message
| I think all the languages allow nulls. I know VB does. |
Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it! | Top |
|
Posted by
| Nick Gammon
Australia (23,072 posts) Bio
Forum Administrator |
Date
| Reply #2 on Fri 10 Dec 2004 12:52 AM (UTC) |
Message
| It's the way that data is passed into MUSHclient that is the problem. Here is the code for Base64Encode, for example:
VARIANT CMUSHclientDoc::Base64Encode(LPCTSTR Text, BOOL MultiLine)
{
int len = strlen (Text);
...
}
The first thing it does is find the length of the supplied text by doing strlen, which searches for a null. That terminates the string.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Flannel
USA (1,230 posts) Bio
|
Date
| Reply #3 on Fri 10 Dec 2004 01:04 AM (UTC) |
Message
| Thats passing back into MC from... what? the lua dll? is that before or after compression? (passed into MC proper? or passed into MC's zlib?)
So does Lua use PWSZ strings? or still BSTRs?
and shouldnt the workaround be easy enough? |
~Flannel
Messiah of Rose
Eternity's Trials.
Clones are people two. | Top |
|
Posted by
| Nick Gammon
Australia (23,072 posts) Bio
Forum Administrator |
Date
| Reply #4 on Fri 10 Dec 2004 01:26 AM (UTC) |
Message
| That's the code generated when I do a COM interface, in this case from a script language, other than Lua, into MUSHclient. The LPCTSTR data type is a long pointer to a C-string. A C-string is a null-terminated one.
However with Lua the scripting interface is different, it does not rely on COM. Thus, if I expect nulls in strings, which I do for something like a hash, encryption or (de)compression, then I ask Lua for a string, and a length, as 2 separate fields. That way imbedded nulls don't affect the result.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Poromenos
Greece (1,037 posts) Bio
|
Date
| Reply #5 on Fri 10 Dec 2004 07:30 AM (UTC) |
Message
| Hmm, I don't remember much about C++ strings, but I think that the STL and MFC string types allow nulls in them. I don't know if you could change all the declarations to that type though. |
Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it! | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
24,458 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top