| 1 |
package packet |
| 2 |
|
| 3 |
// Notation type represents a Notation Data subpacket |
| 4 |
// see https://tools.ietf.org/html/rfc4880#section-5.2.3.16 |
| 5 |
type Notation struct { |
| 6 |
Name string |
| 7 |
Value []byte |
| 8 |
IsCritical bool |
| 9 |
IsHumanReadable bool |
| 10 |
} |
| 11 |
|
| 12 |
func (notation *Notation) getData() []byte { |
| 13 |
nameData := []byte(notation.Name) |
| 14 |
nameLen := len(nameData) |
| 15 |
valueLen := len(notation.Value) |
| 16 |
|
| 17 |
data := make([]byte, 8+nameLen+valueLen) |
| 18 |
if notation.IsHumanReadable { |
| 19 |
data[0] = 0x80 |
| 20 |
} |
| 21 |
|
| 22 |
data[4] = byte(nameLen >> 8) |
| 23 |
data[5] = byte(nameLen) |
| 24 |
data[6] = byte(valueLen >> 8) |
| 25 |
data[7] = byte(valueLen) |
| 26 |
copy(data[8:8+nameLen], nameData) |
| 27 |
copy(data[8+nameLen:], notation.Value) |
| 28 |
return data |
| 29 |
} |