> I would always have to look up the forum syntax how to do that.
the markdown code block is used literally on every forum, IM or any place where
you can leave a comment.
1. I _did_ describe my solution
2. I don't react as desired to paternalizing and trying to paint me as a bad
guy without a social conscience. Quite the contrary.
3. I try to avoid putting code here because I would always have to look up
the forum syntax how to do that.
> Anyway, I have found a working solution now after a lot of research
_...and as a good citizen, I will post it here so when somebody after me
struggles with the same issue, can see how I managed to solve it._
Yes that's one way but not what I want. I mean, come on, it's not something
exotic to binary read/write from/to disk.
Anyway, I have found a working solution now after a lot of research. Thank you
all for sharing your thoughts.
i would just safe the string representation of the ip addr. And would call
"parseIpAddress" when i want to read it in again.
Object variants use a discrimining first byte + the size of the biggest
contained object so 1+16 bytes here.
This follows C representation but you can't rely on it. Also C compilers are
free to leave garbage in [4 .. 15] if you are on IPv4 branch.
Yes, of course your suggested solution looks more secure. But do you know why
it is dangerous to just read the full object at once as in his first post? And
maybe you can give a full example -- write family field, write data, and later
read both back.
I'm not familiar with the IP object but given it's definition:
type IpAddress = object
case family*: IpAddressFamily ## the type of the IP address (IPv4 or IPv6)
of IpAddressFamily.IPv6:
address_v6*: array[0 .. 15, uint8] ## Contains the IP address in
bytes in
I'm a human. _Of course_ I use higher level functionality when available and
adequate. I'm no less lazy than others - g
For configs for example I use high level modules (like json). But for some
things the ugly old way of using low level binary writing is needed.
Btw: I'm less afraid than many
> (again: Docs! We need good docs if we want Nim to become a language for
> professional use!)
Note: Using low level routines like fstream.readData() with addr() for higher
level data like objects or strings is newer a good decision. Internals of these
data structures may change without notice,
Update:
Now it works (with my real world code). Kind of. But now the problem has
shifted to a string field right after the IpAddress field of my struct/object.
As I need to be productive I can't afford to lose a lot of time digging through
Nim's libraries' sources (again: Docs! We need good doc
Yes, that's in part what this (and, I assume, the problem) is about. I _did_
study the doc (and the source) carefully.
More docs on Nim "toBinary" and "fromBinary" magic in types, used. eg. in
FileStream read and write would be urgently needed IMHO.
> The test code is a simple fstream.readData(ipa.addr, ipa.sizeof) with ipa
> being a var IpAddress
I would be very carefully doing that, as IpAddress seems to be a Sum
Type/UniounType/Object variant. It may work without problems, just I am not
sure.
[https://nim-lang.org/docs/net.html#IpAddre
The test code is a simple `fstream.readData(ipa.addr, ipa.sizeoff)` with `ipa`
being an `IpAddress` and a prior `fstream.write(ipa)`.
The problem seems not to appear in very simple code like write one IP then
another one and then a third one ... and then read them back just as simply. In
my rea
It's probably specific to your code, so a code paste would be helpful.
Trying to write and read `IpAddress` from/to disk via `readData(x.addr,
x.sizeof)` and `write(x)` seems to be flakey when both Ipv4 and IPv6 addresses
are used. Using IPv4 alone seems to work.
Also, (using Nim 0.19.1/linux) I can't set the `address_vX` fields of
`IpAddress` ("cannot prove ... f
16 matches
Mail list logo