macmaskarg.go
func (m *MACMaskArg) MarshalBinary() ([]byte, error) {
	// Must indicate correct number of directives
	if int(m.DirCount) != len(m.Directives) {
		return nil, ErrorBadArgumentParameter
	}

	// Allocate byte slice for argument and all directives
	b := make([]byte, macMaskArgLen+(directiveLen*m.DirCount))

	// 1 byte reserved

	b[1] = uint8(m.Command)
	b[2] = uint8(m.Error)
	b[3] = m.DirCount

	// Marshal each directive into binary and copy into byte slice
	// after argument
	n := 4
	for _, d := range m.Directives {
		db, err := d.MarshalBinary()
		if err != nil {
			return nil, err
		}

		copy(b[n:n+directiveLen], db)
		n += directiveLen
	}

	return b, nil
}
func (m *MACMaskArg) MarshalBinary() ([]byte, error) {
	// Must indicate correct number of directives
	if int(m.DirCount) != len(m.Directives) {
		return nil, ErrorBadArgumentParameter
	}

	// Allocate byte slice for argument and all directives
	b := make([]byte, macMaskArgLen+(directiveLen*m.DirCount))

	// 1 byte reserved

	b[1] = uint8(m.Command)
	b[2] = uint8(m.Error)
	b[3] = m.DirCount

	// Marshal each directive into binary and copy into byte slice
	// after argument
	n := 4
	for _, d := range m.Directives {
		db, err := d.MarshalBinary()
		if err != nil {
			return nil, err
		}

		copy(b[n:n+directiveLen], db)
		n += directiveLen
	}

	return b, nil
}
func ( m * MACMaskArg ) MarshalBinary ( ) ( [ ] byte , error ) { // Must indicate correct number of directives if int ( m . DirCount ) != len ( m . Directives ) { return nil , ErrorBadArgumentParameter } // Allocate byte slice for argument and all directives b := make ( [ ] byte , macMaskArgLen + ( directiveLen * m . DirCount ) ) // 1 byte reserved b [ 1 ] = uint8 ( m . Command ) b [ 2 ] = uint8 ( m . Error ) b [ 3 ] = m . DirCount // Marshal each directive into binary and copy into byte slice // after argument n := 4 for _ , d := range m . Directives { db , err := d . MarshalBinary ( ) if err != nil { return nil , err } copy ( b [ n : n + directiveLen ] , db ) n += directiveLen } return b , nil }
// MarshalBinary allocates a byte slice containing the data from a MACMaskArg.
//
// If m.DirCount does not indicate the actual length of m.Directives, or
// a Directive is malformed, ErrorBadArgumentParameter is returned.
MarshalBinary allocates a byte slice containing the data from a MACMaskArg . If m . DirCount does not indicate the actual length of m . Directives or a Directive is malformed ErrorBadArgumentParameter is returned .