使用golang提取TCP有效负载中的自定义数据格式

I have an industrial sensor which is connected to a Interface Module that provides information to the end user via telnet.

Telnet Configuration

Port: 10001

Data Format: Little-Endian

Data payload

Preamble - 32 bit
Article number - 32 bit
Serial number - 32 bit
Channels - 64 bit
Status - 32 bit
Frame number M / - 16 bit/ 16 bit
bytes per frame
Measuring value counter - 32 bit
Measuring value frame 1 - N * 32 bit
..
..

This should be available after the TCP headers (if I understand correctly) i.e. Payload.

I am trying to learn golang with more practical examples and I am thinking in the following direction:

  1. Create a TCP server for listening to the sensor's Interface module IP and port number
  2. Extract the payload and just print it out as seperate parameters like preamble, article number etc. as a beginners task

I have gone through some blog-posts about TCP server/client creations but they only address string in their payload. How can I extract such a byte orientated custom payload as mentioned above?

P.S.

I can understand that this can be achieved in python probably via struct.pack and struct.unpack hence some correlation as understanding would be appreciated

In section 6.2 of your linked pdf document above there is a table listing the data you seem to list in the question

I would convert that table into a struct and then read into it with the encoding/binary module. See https://golang.org/pkg/encoding/binary/#example_Read for a relevant example

"All measuring values are transmitted as Int32, Uint32 or Float depending on the connected sensor" probably easiest to get them as uint32 and then convert them later