)
type Transaction struct {
- Flags byte // Reserved (should be 0)
- IsReply byte // Request (0) or reply (1)
- Type []byte // Requested operation (user defined)
- ID []byte // Unique transaction ID (must be != 0)
- ErrorCode []byte // Used in the reply (user defined, 0 = no error)
- TotalSize []byte // Total data size for the transaction (all parts)
- DataSize []byte // Size of data in this transaction part. This allows splitting large transactions into smaller parts.
- ParamCount []byte // Number of the parameters for this transaction
+ Flags byte // Reserved (should be 0)
+ IsReply byte // Request (0) or reply (1)
+ Type [2]byte // Requested operation (user defined)
+ ID [4]byte // Unique transaction ID (must be != 0)
+ ErrorCode [4]byte // Used in the reply (user defined, 0 = no error)
+ TotalSize [4]byte // Total data size for the transaction (all parts)
+ DataSize [4]byte // Size of data in this transaction part. This allows splitting large transactions into smaller parts.
+ ParamCount [2]byte // Number of the parameters for this transaction
Fields []Field
clientID *[]byte // Internal identifier for target client
binary.BigEndian.PutUint32(idSlice, rand.Uint32())
return &Transaction{
- clientID: clientID,
- Flags: 0x00,
- IsReply: 0x00,
- Type: typeSlice,
- ID: idSlice,
- ErrorCode: []byte{0, 0, 0, 0},
- Fields: fields,
+ clientID: clientID,
+ Type: [2]byte(typeSlice),
+ ID: [4]byte(idSlice),
+ Fields: fields,
}
}
t.Flags = p[0]
t.IsReply = p[1]
- t.Type = p[2:4]
- t.ID = p[4:8]
- t.ErrorCode = p[8:12]
- t.TotalSize = p[12:16]
- t.DataSize = p[16:20]
- t.ParamCount = p[20:22]
+ t.Type = [2]byte(p[2:4])
+ t.ID = [4]byte(p[4:8])
+ t.ErrorCode = [4]byte(p[8:12])
+ t.TotalSize = [4]byte(p[12:16])
+ t.DataSize = [4]byte(p[16:20])
+ t.ParamCount = [2]byte(p[20:22])
return len(p), err
}
buf := slices.Concat(
[]byte{t.Flags, t.IsReply},
- t.Type,
- t.ID,
- t.ErrorCode,
+ t.Type[:],
+ t.ID[:],
+ t.ErrorCode[:],
payloadSize,
payloadSize, // this is the dataSize field, but seeming the same as totalSize
fieldCount,
}
func (t *Transaction) IsError() bool {
- return bytes.Equal(t.ErrorCode, []byte{0, 0, 0, 1})
+ return t.ErrorCode == [4]byte{0, 0, 0, 1}
}