How do `Map<String, String>` get to know, the `String` endings in `MethodChannel` arguments - string

If dart and kotlin code communicate through binary(array of 8-bit integers (0-255)), then how does String end or even int end is represented in, or determined from binary sequence of bytes, is there some special charCode or something else.
Also is there a way to save a List<int> as-it-is to a file.txt, so it can be read directly to List<int> instead of serialization.
Please guide this new dev,
Thanking you...

Since Flutter handles the MethodChannel, in both the Dart side and Kotlin side, it can be allowed to have its own internal protocol to communicate between the native layer and Flutter. In theory they could use JSON but they are probably using something else based on the supported types and also making it more efficient: https://docs.flutter.dev/development/platform-integration/platform-channels?tab=type-mappings-kotlin-tab#codec
For saving a List<int> to a file, you need to determine how you want to encode the content in the file and then how you want to decode it. It can be as simply as just saving each number separated by comma or encode the list into JSON.
If your list of numbers can be represented with Uint8List or Int8List, then you can basically just save the numbers as raw bytes to the file and then read them again.
But List<int> is a list of 64-bit numbers and you should therefore determine how you want to encode this exactly.
For writing to files, there are several ways to do it but the specific way depends on what you exactly want. So without any more details I can just suggest you check the API: https://api.dart.dev/stable/2.17.3/dart-io/File-class.html

Related

Jpos Generic Packager XML

Im currently working with Jpos and created an xml for a process that has the description
ASCII/Packed Maps/Unpacked Numerics/ Var Len
I The xml works correctly with this process. I now want to make a second one for a process that rather than Unpacked Numerics it uses packed Numerics but im not sure what jpos classes would do this.
Iv tried changing all the IFA_Numerics to IFB_numerics and IFA_LLNUM to IFB_LLNUM but that didnt work
What classes represent packed numerics???
So after looking through the process some more i found that it wants the length displayed not in binary so i needed to use the IFB_LLHNUM to indicate the datatype of the length

String to \x escaped hex ascii

i am working with sockets (some DNS stuff) and i can't figure out how from this:
a = 'www'
make
b = b'\x77\x77\x77'
I know/think i need to:
1) convert each to hex value with hex(ord(char))
2) format it from '0x77' to '\x77'
3) convert it to bytes with bytes(a,'utf-8')
I tried many combinations, but i always failed at 2) and generally i think my steps are too complicated. Is there some simple solution to this?
I'll attempt an answer.
What you wish to do is work with the binary messages being exchanged with a DNS server.
You are wondering how to convert strings and integers into into the binary form.
Have a look at the struct module to pack and unpack binary messages.
You will also need to convert IP addresses from there binary form into strings.
Have a look at socket.inet_ntoa and socket.inet_aton.
Barry

Create an NSData object from a String

My app requires the ability to take a String and save it to an NSDictionary as an NSData object, such that when the NSDictionary is written to a .plist file the resulting file contains the data as <data>The String as the user typed it (no encoding)</data>. Is there anyway to do that without manually writing the XML for the .plist file?
Thanks in advance for any help.
There's no way to do what you want.
First, it makes no sense to claim that you don't want the string encoded. Encoding is the process of producing a byte stream from a string. Without encoding, there's no representation of the string. Strings are abstract. They have no concrete representation in and of themselves. Only encoding produces that.
Anyway, that's just not how NSData objects are serialized to property list files. Even if you manually wrote the file, it wouldn't really be a correct property list file and no other property-list-reading program would be able to parse it. How did you come to conclude that your app requires this ability?

Md5-Hash-ByteArray is working in programm but not in external validator, (need to convert it to some kind of String)

I am creating a raw MD5-Bytearray of some file and store it in a DB. Then, when I upload the file I validate the Checksum. So far everything works fine.
Now I am trying to display the Checksum in the standard form like, for example, this:
0709bfccaec24cbb5734b905dda8d616
but all I got were some cryptic things, e.g.
[B#1fd3b78a
How do I best get the String?
So the representation I was looking for is appearantly the Hexadezimal representation of the bytes. I converted and saved it as a String:
How to convert a byte array to a hex string in Java?

Groovy says my Unicode string is too long

As part of my probably wrong and cumbersome solution to print out a form I have taken a MS-Word document, saved as XML and I'm trying to store that XML as a groovy string so that I can ${fillOutTheFormProgrammatically}
However, with MS-Word documents being as large as they are, the String is 113100 unicode characters and Groovy says its limited to 65536. Is there some way to change this or am I stuck with splitting up the string?
Groovy - need to make a printable form
That's what I'm trying to do.
Update: to be clear its too long of a Groovy String.. I think a regular string might be all good. Going to change strategy and put some strings in the file I can easily find like %!%variable_name%!% and then do .replace(... uh i feel a new question coming on here...
Are you embedding this string directly in your groovy code? The jvm itself has a limit on the length of string constants, see the VM Spec if you are interested in details.
A ugly workaround might be to split the string in smaller parts and concatenate them at runtime. A better solution would be to save the text in an external file and read the contents from your code. You could also package this file along with your code and access it from the classpath using Class#getResourceAsStream.

Resources