| ▲ | guappa 7 months ago |
| Go is very boilerplate. It requires at least 3 lines of error checking every 1 line of actual code. Also it doesn't have packed structs so it's completely incapable of doing low level networking or to handle binary files (you can of course do all the bitwise operations yourself… but is it sensible to use a language that is more error prone than C in 2024?). Also due to its lack of A LOT of system calls, you will need to use modules written by someone on github, which will happily segfault if you look at them funny. So now you have hidden memory management! Fun! Of course if all you do with go is a glorified jq script… sure then it's kinda fine. |
|
| ▲ | mrbadguy 7 months ago | parent | next [-] |
| I’m not sure I understand the packed structs complaint. I have used Go to read binary data and it’s quite easy. You just need to ensure that all of your struct fields have fixed sizes e.g. int32 or [4]int64 or whatever. Unless I’ve misunderstood what you mean? |
| |
| ▲ | guappa 7 months ago | parent [-] | | Yes it works, but you can't state the endianness and you have no control to decide if the compiler will decide to insert padding. It's undefined. You HOPE it works. | | |
| ▲ | mrbadguy 7 months ago | parent [-] | | I don’t know about the padding (certainly it never inserted any when I’ve used it) but you can definitely state the byte order upon reading or writing. That would definitely be an oversight. Take a look at the encoding/binary package: https://pkg.go.dev/encoding/binary | | |
| ▲ | guappa 7 months ago | parent [-] | | I want a struct, not to having to write the code manually to do a struct every single time. I know you can do that in go but as I already said: "more error prone than C". | | |
| ▲ | mrbadguy 7 months ago | parent [-] | | Can you please give me an example of what you don’t like? I’m not sure I understand the “write the code manually to do a struct” bit. You have to define the struct for sure, but beyond that you just pass it to binary.Read and it comes back with the fields populated. I don’t see how you’d avoid defining the struct. | | |
| ▲ | dfawcus 7 months ago | parent [-] | | I believe what he wants, is the usual C trick of defining a struct which represents the wire format (with all the usual caveats). Then cast a char pointer to be an instance of a pointer to that struct. Sort of like this: https://github.com/danos/vyatta-dataplane/blob/master/src/ecmp.c#L108-L116
It sort of works on x86 chips, but is not so effective on MIPS, PPC, etc where misaligned access are either unavailable, or slow, or even trap and are slower still.Once one has to handle that sort of situation, and actually copy the data, the lack of language support for such type-punning becomes immaterial. | | |
| ▲ | mrbadguy 7 months ago | parent | next [-] | | Oh I see, thanks for the clarification! Personally, I'm fine without that and with something like func Foo(r io.Reader) {
var m MyStruct
binary.Read(r, binary.LittleEndian, &m)
}
but we may be operating in different contexts where the underlying copy is or isn't a problem. That said, depending on the implementation of the reader passed in, the bytes might be being streamed from elsewhere, in which case the copying is minimised. | |
| ▲ | guappa 7 months ago | parent | prev [-] | | https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.ht... If the misaligned access is slow… it will be slow whether the compiler reads the variable or if you hand-write even slower and error prone code. That said, please show me a protocol that generates unaligned accesses on any architecture. People writing protocols aren't noobs :) |
|
|
|
|
|
|
|
| ▲ | dfawcus 7 months ago | parent | prev | next [-] |
| How low level a networking use do you desire? I certainly managed to use it to implement a protocol over UDP without any issues, that having byte and bit packed values. Or do you wish to have something similar to C with structs and (endian dependent) bitfields overlaid on packet buffers? |
| |
| ▲ | guappa 7 months ago | parent [-] | | > Or do you wish to have something similar to C with structs and (endian dependent) bitfields overlaid on packet buffers? endian dependent until you tell gcc which endianness you want :) Which you can't do in go. |
|
|
| ▲ | underdeserver 7 months ago | parent | prev [-] |
| I worked on a project with gopacket. It was completely fine. |
| |