Ember+ loadable plugin
Source
// DecodeUniversal decoded the following universal data type of glow, currently only used for universal path decoding,
/*
** Copyright (C) 2001-2024 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
package asn1
import (
"errors"
"io"
"golang.zabbix.com/sdk/errs"
)
// Read reads the next glow data block of the appropriate type, it checks the glow tag against the provided compare
// function and if they match it reads the glow data block and returns it as it's own decoded, original decoder might
// have more data left, THIS DOES NOT READ ALL THE DATA.
// If no length byte is found in data returns ALL remaining bytes.
// Returns True if next element length is unknown.
func (c *Decoder) Read(tag uint8, compareByte func(num uint8) uint8) (*Decoder, bool, error) {
b, err := c.data.ReadByte()
if err != nil {
return nil, false, errs.Wrap(err, "failed to read tag byte")
}
if b != compareByte(tag) {
return nil, false, errs.Errorf("is not correct byte: %x got %x", compareByte(tag), b)
}
lenB, _, err := c.readLength()
if err != nil {
if !errors.Is(err, ErrNoLenByte) {
return nil, false, errs.Wrap(err, "failed to read length byte")
}
var out []byte
out, err = c.readWithOutLength()
if err != nil {
return nil, false, errs.Wrap(err, "failed to read with out provided length")
}
return NewDecoder(out), true, nil
}
out, err := c.readWithLength(lenB)
if err != nil {
return nil, false, errs.Wrap(err, "failed to read with provided length")
}
return NewDecoder(out), false, nil
}
// readLength reads next in line data blocks length and returns it as well as how many bytes the data