-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: добавлена секция EGTS_SR_DISPATCHER_IDENTITY
- Loading branch information
1 parent
9df1f74
commit 87c8cb6
Showing
4 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package egts | ||
|
||
import ( | ||
"bytes" | ||
"encoding/binary" | ||
"fmt" | ||
) | ||
|
||
// SrDispatcherIdentity структура подзаписи типа EGTS_SR_DISPATCHER_IDENTITY, которая используется | ||
//только авторизуемой ТП при запросе авторизации на авторизующей ТП и содержит учетные данные | ||
//авторизуемой АСН | ||
type SrDispatcherIdentity struct { | ||
DispatcherType uint8 `json:"DT"` | ||
DispatcherID uint32 `json:"DID"` | ||
Description string `json:"DSCR"` | ||
} | ||
|
||
// Decode разбирает байты в структуру подзаписи | ||
func (d *SrDispatcherIdentity) Decode(content []byte) error { | ||
var err error | ||
|
||
buf := bytes.NewBuffer(content) | ||
|
||
if d.DispatcherType, err = buf.ReadByte(); err != nil { | ||
return fmt.Errorf("Не удалось получить тип диспетчера: %v", err) | ||
} | ||
|
||
tmpIntBuf := make([]byte, 4) | ||
if _, err = buf.Read(tmpIntBuf); err != nil { | ||
return fmt.Errorf("Не удалось получить уникальный идентификатор диспетчера: %v", err) | ||
} | ||
d.DispatcherID = binary.LittleEndian.Uint32(tmpIntBuf) | ||
|
||
d.Description = buf.String() | ||
|
||
return err | ||
} | ||
|
||
// Encode преобразовывает подзапись в набор байт | ||
func (d *SrDispatcherIdentity) Encode() ([]byte, error) { | ||
var ( | ||
result []byte | ||
err error | ||
) | ||
|
||
buf := new(bytes.Buffer) | ||
|
||
if err = buf.WriteByte(d.DispatcherType); err != nil { | ||
return result, fmt.Errorf("Не удалось записать тип диспетчера: %v", err) | ||
} | ||
|
||
if err = binary.Write(buf, binary.LittleEndian, d.DispatcherID); err != nil { | ||
return result, fmt.Errorf("Не удалось записать уникальный идентификатор диспетчера: %v", err) | ||
} | ||
|
||
if _, err = buf.WriteString(d.Description); err != nil { | ||
return result, fmt.Errorf("Не удалось записать уникальный краткое описание: %v", err) | ||
} | ||
|
||
return buf.Bytes(), err | ||
} | ||
|
||
//Length получает длинну закодированной подзаписи | ||
func (d *SrDispatcherIdentity) Length() uint16 { | ||
var result uint16 | ||
|
||
if recBytes, err := d.Encode(); err != nil { | ||
result = uint16(0) | ||
} else { | ||
result = uint16(len(recBytes)) | ||
} | ||
|
||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package egts | ||
|
||
import ( | ||
"github.com/google/go-cmp/cmp" | ||
"testing" | ||
) | ||
|
||
var ( | ||
srDispatcherIdentityPkgBytes = []byte{0x01, 0x00, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x01, 0x00, | ||
0x01, 0x06, 0x08, 0x00, 0x00, 0x00, 0x98, 0x01, 0x01, 0x05, 0x05, 0x00, 0x00, 0x47, 0x00, | ||
0x00, 0x00, 0x51, 0x9d} | ||
|
||
testDispatcherIdentityPkg = Package{ | ||
ProtocolVersion: 1, | ||
SecurityKeyID: 0, | ||
Prefix: "00", | ||
Route: "0", | ||
EncryptionAlg: "00", | ||
Compression: "0", | ||
Priority: "00", | ||
HeaderLength: 11, | ||
HeaderEncoding: 0, | ||
FrameDataLength: 15, | ||
PacketIdentifier: 1, | ||
PacketType: PtAppdataPacket, | ||
HeaderCheckSum: 6, | ||
ServicesFrameData: &ServiceDataSet{ | ||
{ | ||
RecordLength: 0x08, | ||
SourceServiceOnDevice: "1", | ||
RecipientServiceOnDevice: "0", | ||
Group: "0", | ||
RecordProcessingPriority: "11", | ||
TimeFieldExists: "0", | ||
EventIDFieldExists: "0", | ||
ObjectIDFieldExists: "0", | ||
SourceServiceType: 0x01, | ||
RecipientServiceType: 0x01, | ||
RecordDataSet: RecordDataSet{ | ||
{ | ||
SubrecordType: 0x05, | ||
SubrecordLength: 0x05, | ||
SubrecordData: &SrDispatcherIdentity{ | ||
DispatcherType: 0, | ||
DispatcherID: 71, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
ServicesFrameDataCheckSum: 40273, | ||
} | ||
) | ||
|
||
func TestEgtsSrDispatcherIdentity_Encode(t *testing.T) { | ||
authInfoPkg, err := testAuthInfoPkg.Encode() | ||
if err != nil { | ||
t.Errorf("Ошибка кодирования: %v\n", err) | ||
} | ||
|
||
if diff := cmp.Diff(authInfoPkg, srAuthInfoPkgBytes); diff != "" { | ||
t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) | ||
} | ||
} | ||
|
||
func TestEgtsSrDispatcherIdentity_Decode(t *testing.T) { | ||
authPkg := Package{} | ||
|
||
if _, err := authPkg.Decode(srDispatcherIdentityPkgBytes); err != nil { | ||
t.Errorf("Ошибка декодирования: %v\n", err) | ||
} | ||
|
||
if diff := cmp.Diff(authPkg, testDispatcherIdentityPkg); diff != "" { | ||
t.Errorf("Записи не совпадают: (-нужно +сейчас)\n%s", diff) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters