Jump to content

Flatten to String for variants


Recommended Posts

Hi,

I'm working on a little messaging framework to send data over TCP between two machines. That's simple enough, and I thought I'd save myself a bit of work when sending complex data types by converting them to variants and then flattening the variants to strings.

What I didn't realize is that "Variant to Flattened String" doesn't really flatten into a string, but into a string and an array of integers. That doesn't really help for sending data over TCP, unless I cluster that up, flatten the cluster and send that. Ick.

Is it necessary to use "Variant to Flattened String"? My cursory testing indicates that "Flatten to String" works fine for variants; I haven't found a case where it fails. Note that I'm not interested in using any of the fancy features of variants in this case.

The online help and examples do not bother to go into the whys and wherefores, and so are unhelpful for this!

Thanks for illuminating me,

Link to comment

Variant to Flattened String and Flatten to String both act exactly the same when used on typed data.

When used with a variant input, Variant to Flattened String returns the flattened string of the data contained in the variant, same as is contained data was input to Flatten to String

When used with a variant input, Flatten to String returns the flatttened data of the variant, e.g. the flattened data of the contained typed data plus the flattened type descriptor of the the typed data. When you send that thru TCP, the variant is exactly reconstructed with its contained typed data so it is safe to use.

Link to comment

QUOTE(Guillaume Lessard @ Jul 5 2007, 11:45 PM)

Hi,

I'm working on a little messaging framework to send data over TCP between two machines. That's simple enough, and I thought I'd save myself a bit of work when sending complex data types by converting them to variants and then flattening the variants to strings.

What I didn't realize is that "Variant to Flattened String" doesn't really flatten into a string, but into a string and an array of integers. That doesn't really help for sending data over TCP, unless I cluster that up, flatten the cluster and send that. Ick.

[...]

Assuming you don't care too much how verbose your TCP transmissions are, why not use the (un)flatten to/from XML functions ? They (obviously) don't use a type descriptor array and with the string data being human readable it might be easier to debug if the conversion failed...

Link to comment

One thing to add, make sure the '(Un) flatten to/from string' functions are in the same LabVIEW version.

Variants have been known to change from version to version, most of the time a compatibility mode is available (see in 8.x the 'Unflatten from string' right click)

Ton

Link to comment

QUOTE(Gavin Burnell @ Jul 6 2007, 02:35 PM)

Assuming you don't care too much how verbose your TCP transmissions are, why not use the (un)flatten to/from XML functions ? They (obviously) don't use a type descriptor array and with the string data being human readable it might be easier to debug if the conversion failed...

These functions are substantially slower than the raw Flatten/Unflatten. Fine for a final write out to file, but not something I'd want in a loop.

Sparc

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.