// bytesBinaryReader reads bytes from io.Reader and returns byte slice of
// specified size or the error encountered while trying to read those bytes.
437578
func bytesBinaryReader(ior io.Reader) ([]byte, error) {
	size, err := longBinaryReader(ior)
	if err != nil {
		return nil, fmt.Errorf("cannot read bytes: cannot read size: %s", err)
	}
	if size < 0 {
		return nil, fmt.Errorf("cannot read bytes: size is negative: %d", size)
	}
	if size > MaxBlockSize {
		return nil, fmt.Errorf("cannot read bytes: size exceeds MaxBlockSize: %d > %d", size, MaxBlockSize)
	}
	buf := make([]byte, size)
	_, err = io.ReadAtLeast(ior, buf, int(size))
	if err != nil {
		return nil, fmt.Errorf("cannot read bytes: %s", err)
	}
	return buf, nil
}
999716
func (p DataFragmentPayload) MarshalBinary() ([]byte, error) {
	b := make([]byte, p.Size())

	binary.LittleEndian.PutUint16(b[0:2], p.IndexAndN.N&0x3fff)
	b[1] |= (p.IndexAndN.FragIndex & 0x03) << 6
	copy(b[2:], p.Payload)

	return b, nil
}
199537
func (hmac HMAC) MarshalBinary() (data []byte, err error) {
	return hmac.h.MarshalBinary()
}
353611
func (r *ReplyGetattrV2) MarshalBinary() ([]byte, error) {
	return MarshalBinary(&r.Reply, &r.Attr, &r.SymlinkTarget)
}
442580
func (m *EndpointNetworking) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}
1350463
func (m *IpvlanConfiguration) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}
249951
func (p DLChannelAnsPayload) MarshalBinary() ([]byte, error) {
	var b byte
	if p.ChannelFrequencyOK {
		b = b ^ 1
	}
	if p.UplinkFrequencyExists {
		b = b ^ (1 << 1)
	}
	return []byte{b}, nil
}
374066
func MarshalBinary(fields ...interface{}) ([]byte, error) {
	buf := new(bytes.Buffer)

	for _, p := range fields {
		switch m := p.(type) {
		case encoding.BinaryMarshaler:
			data, err := m.MarshalBinary()
			if err != nil {
				return nil, ProtocolError(err)
			}

			_, _ = buf.Write(data)
		case []byte:
			_, _ = buf.Write(m)
		case string:
			_, _ = buf.WriteString(m)
		default:
			err := binary.Write(buf, binary.LittleEndian, p)
			if err != nil {
				return nil, ProtocolError(err)
			}
		}
	}

	return buf.Bytes(), nil
}
126748
func (s *StatusCode) MarshalBinary() ([]byte, error) {
	// 2 bytes: status code
	// N bytes: message
	b := buffer.New(nil)
	b.Write16(uint16(s.Code))
	b.WriteBytes([]byte(s.Message))
	return b.Data(), nil
}
595870
func (m *DaemonConfigurationSpec) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}
184540
func (p NewChannelAnsPayload) MarshalBinary() ([]byte, error) {
	var b byte
	if p.ChannelFrequencyOK {
		b = (1 << 0)
	}
	if p.DataRateRangeOK {
		b = b ^ (1 << 1)
	}
	return []byte{b}, nil
}
285898
func (p *TCompactProtocol) ReadBinary() (value []byte, err error) {
	length, e := p.readVarint32()
	if e != nil {
		return []byte{}, NewTProtocolException(e)
	}
	if length == 0 {
		return []byte{}, nil
	}

	buf := make([]byte, length)
	_, e = io.ReadFull(p.trans, buf)
	return buf, NewTProtocolException(e)
}
926388
func decodeBinary(rd *bufio.Reader) (string, Binary, error) {
	// name
	name, err := readCstring(rd)
	if err != nil {
		return "", nil, err
	}

	// value
	dataLen, err := readInt32(rd)
	if err != nil {
		return "", nil, err
	}

	// discard subtype
	_, err = rd.ReadByte()
	if err != nil {
		return "", nil, err
	}
	b := make([]byte, dataLen)
	_, err = io.ReadFull(rd, b)
	if err != nil {
		return "", nil, err
	}
	return name, Binary(b), nil
}
23582
func (h TLFReaderKeyBundleID) MarshalBinary() (data []byte, err error) {
	return h.h.MarshalBinary()
}
524261
func (m *SwaggerJSONWebKey) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}
816011
func (f *Frame) MarshalBinary() ([]byte, error) {
	b := make([]byte, f.length())
	_, err := f.read(b)
	return b, err
}
147507
func (m *StatusResponseKubernetes) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}