2019-11-05 15:47:30 +00:00
|
|
|
package sii
|
|
|
|
|
|
|
|
type Block interface {
|
2019-11-05 22:00:57 +00:00
|
|
|
Class() string
|
|
|
|
Init(class, name string)
|
2019-11-05 15:47:30 +00:00
|
|
|
Name() string
|
|
|
|
}
|
|
|
|
|
|
|
|
type Marshaler interface {
|
|
|
|
MarshalSII() ([]byte, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Unmarshaler interface {
|
|
|
|
UnmarshalSII([]byte) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type RawBlock struct {
|
|
|
|
Data []byte
|
|
|
|
|
2019-11-05 22:00:57 +00:00
|
|
|
blockName string
|
|
|
|
blockClass string
|
2019-11-05 15:47:30 +00:00
|
|
|
}
|
|
|
|
|
2019-11-05 22:00:57 +00:00
|
|
|
func (r *RawBlock) Init(class, name string) {
|
|
|
|
r.blockClass = class
|
|
|
|
r.blockName = name
|
|
|
|
}
|
2019-12-10 22:20:25 +00:00
|
|
|
func (r RawBlock) MarshalSII() ([]byte, error) { return r.Data, nil }
|
|
|
|
func (r RawBlock) Name() string { return r.blockName }
|
|
|
|
func (r RawBlock) Class() string { return r.blockClass }
|
2019-11-05 22:00:57 +00:00
|
|
|
func (r *RawBlock) UnmarshalSII(in []byte) error {
|
2019-11-05 15:47:30 +00:00
|
|
|
r.Data = in
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type Unit struct {
|
|
|
|
Entries []Block
|
|
|
|
}
|
2019-12-24 14:07:01 +00:00
|
|
|
|
|
|
|
func (u Unit) BlocksByClass(class string) []Block {
|
|
|
|
var out []Block
|
|
|
|
|
|
|
|
for _, b := range u.Entries {
|
|
|
|
if b.Class() == class {
|
|
|
|
out = append(out, b)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u Unit) BlockByName(name string) Block {
|
|
|
|
for _, b := range u.Entries {
|
|
|
|
if b.Name() == name {
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|