Example #1
0
// PDU returns bytes of semi-octet encoded timestamp.
func (t Timestamp) PDU() []byte {
	date := time.Time(t)
	year := uint64(date.Year() - 2000)
	month := uint64(date.Month())
	day := uint64(date.Day())
	hour := uint64(date.Hour())
	minute := uint64(date.Minute())
	second := uint64(date.Second())
	_, offset := date.Zone()
	quarters := uint64(offset / int(time.Hour/time.Second) * 4)
	return pdu.EncodeSemi(year, month, day, hour, minute, second, quarters)
}
Example #2
0
// PDU returns the number of digits in address and octets of semi-octet encoded address.
func (p PhoneNumber) PDU() (int, []byte, error) {
	digitStr := strings.TrimPrefix(string(p), "+")
	var str string
	for _, r := range digitStr {
		if r >= '0' && r <= '9' {
			str = str + string(r)
		}
	}
	n := len(str)
	number, err := strconv.ParseUint(str, 10, 64)
	if err != nil {
		return 0, nil, err
	}
	var buf bytes.Buffer
	buf.WriteByte(p.Type())
	buf.Write(pdu.EncodeSemi(number))
	return n, buf.Bytes(), nil
}