2024-07-09 23:40:20 -04:00
|
|
|
package wireproto
|
|
|
|
|
|
|
|
import (
|
|
|
|
`encoding/binary`
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// IndentChars is used when rendering a Model; it indicates the leading indent.
|
|
|
|
IndentChars string = IndentDefault
|
|
|
|
// SeparatorChars is used when rendering a Model; it indicates the separation between the value and the comment.
|
|
|
|
SeparatorChars string = SeparatorDefault
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2024-07-10 00:40:12 -04:00
|
|
|
// IndentDefault is the [IndentChars] to use if not specified.
|
2024-07-09 23:40:20 -04:00
|
|
|
IndentDefault string = "\t"
|
2024-07-10 00:40:12 -04:00
|
|
|
// SeperatorDefault is the [SeperatorChars] to use if not specified.
|
2024-07-09 23:40:20 -04:00
|
|
|
SeparatorDefault string = " "
|
2024-07-10 00:40:12 -04:00
|
|
|
maxByteLine int = 12 // (Split a hex string in a Model if a value is more than this number of bytes.)
|
2024-07-09 23:40:20 -04:00
|
|
|
)
|
|
|
|
|
2024-07-10 00:40:12 -04:00
|
|
|
// Default indent levels.
|
2024-07-09 23:40:20 -04:00
|
|
|
const (
|
|
|
|
indentR uint = iota
|
|
|
|
indentRG
|
|
|
|
indentRec
|
|
|
|
indentKvp
|
|
|
|
)
|
|
|
|
const indentOrigRec uint = 2
|
|
|
|
|
|
|
|
const (
|
2024-07-10 00:40:12 -04:00
|
|
|
// ProtoVersion specifies the protocol version for the specification of a [Message].
|
2024-07-09 23:40:20 -04:00
|
|
|
ProtoVersion uint32 = 1
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// PackedNumSize is the size (length of bytes) of a packed unsigned integer.
|
2024-07-10 00:40:12 -04:00
|
|
|
PackedNumSize int = 4 // (They're all uint32's.)
|
2024-07-09 23:40:20 -04:00
|
|
|
// CksumPackedSize is the size (length of bytes) of the checksum algorithm used.
|
2024-07-10 00:40:12 -04:00
|
|
|
CksumPackedSize int = 4 // CRC32 is represented by a big-endian uint32, but if a different algo is used, this will need to be changed.
|
2024-07-09 23:40:20 -04:00
|
|
|
)
|
|
|
|
|
2024-07-10 00:40:12 -04:00
|
|
|
// See https://square-r00t.net/ascii.html for further details on ASCII symbols.
|
2024-07-09 23:40:20 -04:00
|
|
|
const (
|
|
|
|
AsciiNUL uint8 = iota // 0x00
|
|
|
|
AsciiSOH // 0x01
|
|
|
|
AsciiSTX // 0x02
|
|
|
|
AsciiETX // 0x03
|
|
|
|
AsciiEOT // 0x04
|
|
|
|
AsciiENQ // 0x05
|
|
|
|
AsciiACK // 0x06
|
|
|
|
AsciiBEL // 0x07
|
|
|
|
AsciiBS // 0x08
|
|
|
|
AsciiHT // 0x09
|
|
|
|
AsciiLF // 0x0a
|
|
|
|
AsciiVT // 0x0b
|
|
|
|
AsciiFF // 0x0c
|
|
|
|
AsciiCR // 0x0d
|
|
|
|
AsciiSO // 0x0e
|
|
|
|
AsciiSI // 0x0f
|
|
|
|
AsciiDLE // 0x10
|
|
|
|
AsciiDC1 // 0x11
|
|
|
|
AsciiDC2 // 0x12
|
|
|
|
AsciiDC3 // 0x13
|
|
|
|
AsciiDC4 // 0x14
|
|
|
|
AsciiNAK // 0x15
|
|
|
|
AsciiSYN // 0x16
|
|
|
|
AsciiETB // 0x17
|
|
|
|
AsciiCAN // 0x18
|
|
|
|
AsciiEM // 0x19
|
|
|
|
AsciiSUB // 0x1a
|
|
|
|
AsciiESC // 0x1b
|
|
|
|
AsciiFS // 0x1c
|
|
|
|
AsciiGS // 0x1d
|
|
|
|
AsciiRS // 0x1e
|
|
|
|
AsciiUS // 0x1f
|
|
|
|
)
|
|
|
|
|
2024-07-10 00:40:12 -04:00
|
|
|
// Response Status indicator bytes.
|
2024-07-09 23:40:20 -04:00
|
|
|
const (
|
|
|
|
RespStatusByteOK uint8 = AsciiACK
|
|
|
|
RespStatusByteErr = AsciiNAK
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
byteOrder binary.ByteOrder = binary.BigEndian
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
respStatusOK []byte = []byte{RespStatusByteOK}
|
|
|
|
respStatusErr []byte = []byte{RespStatusByteErr}
|
|
|
|
// hdrCKSUM *must* be *exactly* as long as hdrMSGSTART and *must not* match hdrMSGSTART.
|
|
|
|
hdrCKSUM []byte = []byte{AsciiESC}
|
|
|
|
hdrMSGSTART []byte = []byte{AsciiSOH}
|
|
|
|
hdrBODYSTART []byte = []byte{AsciiSTX}
|
|
|
|
hdrBODYEND []byte = []byte{AsciiETX}
|
|
|
|
hdrMSGEND []byte = []byte{AsciiEOT}
|
|
|
|
endSeq []byte = []byte{AsciiETX, AsciiEOT}
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2024-07-10 00:40:12 -04:00
|
|
|
// WriteChunkSize is the default size of chunking to use (in bytes) when using chunked Write* functions (i.e. non-segmented).
|
2024-07-09 23:40:20 -04:00
|
|
|
WriteChunkSize int = 1024
|
|
|
|
)
|