Results 1 to 2 of 2
  1. #1
    Senior Member
    Join Date
    Jul 2013

    How to get byte[] from onItemUpdate properly?


    My data adapter is .NET implementation. Here is code to update to LS client:
    Dictionary<string, byte[]> data = new Dictionary<string, byte[]>();
    data.Add("fieldname1", new byte[] { 65, 66, 67 });
    _listener.Update("item1", data, false);
    As you mentioned in your docs here, this function returns a String.

    How do I properly convert from String to byte[] in my Javascript code?

    Should I use String.getBytes("ISO-8859-1")? Is it platform-independent?

    Thanks in advance,

  2. #2
    Join Date
    Jul 2006
    In fact Lightstreamer client interfaces are based on strings and there isn't an explicit support for the transport of raw bytes.
    You can, of course, transport bytes by encoding them into strings, for instance through a base64 encoding.

    On the other hand, it seems that you would like to transport bytes by leaning on the byte encoding of the strings.
    This should work, because we ensure that a byte array that you submit as a field value is considered as a ISO-8859-1 representation of a string. Because of the properties of the ISO-8859-1 encoding, we can supply that string to javascript as a string literal in which each byte of the original array corresponds to the equivalent ascii character or to an equivalent unicode escape sequence of the form \uXXXX.
    Hence, if you extract each character from the string value through JavaScript's charCodeAt() method, you should retrieve the value of the original byte.
    If you have some getBytes() method available, then invoking getBytes("ISO-8859-1") should work as well.




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
All times are GMT +1. The time now is 01:46 AM.