[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Compression and decompression
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Compression and decompression

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Nick Gammon   Australia  (21,324 posts)  [Biography] 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
[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] 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!
[Go to top] top

Posted by Nick Gammon   Australia  (21,324 posts)  [Biography] 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
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] 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.
[Go to top] top

Posted by Nick Gammon   Australia  (21,324 posts)  [Biography] 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
[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] 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!
[Go to top] 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.


9,956 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]