// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package proto

import (
	protoV2 
	
)

// Size returns the size in bytes of the wire-format encoding of m.
func ( Message) int {
	if  == nil {
		return 0
	}
	 := MessageV2()
	return protoV2.Size()
}

// Marshal returns the wire-format encoding of m.
func ( Message) ([]byte, error) {
	,  := marshalAppend(nil, , false)
	if  == nil {
		 = zeroBytes
	}
	return , 
}

var zeroBytes = make([]byte, 0, 0)

func ( []byte,  Message,  bool) ([]byte, error) {
	if  == nil {
		return nil, ErrNil
	}
	 := MessageV2()
	,  := protoV2.MarshalOptions{
		Deterministic: ,
		AllowPartial:  true,
	}.MarshalAppend(, )
	if  != nil {
		return , 
	}
	if len() == len() {
		if !.ProtoReflect().IsValid() {
			return , ErrNil
		}
	}
	return , checkRequiredNotSet()
}

// Unmarshal parses a wire-format message in b and places the decoded results in m.
//
// Unmarshal resets m before starting to unmarshal, so any existing data in m is always
// removed. Use UnmarshalMerge to preserve and append to existing data.
func ( []byte,  Message) error {
	.Reset()
	return UnmarshalMerge(, )
}

// UnmarshalMerge parses a wire-format message in b and places the decoded results in m.
func ( []byte,  Message) error {
	 := MessageV2()
	,  := protoV2.UnmarshalOptions{
		AllowPartial: true,
		Merge:        true,
	}.UnmarshalState(protoiface.UnmarshalInput{
		Buf:     ,
		Message: .ProtoReflect(),
	})
	if  != nil {
		return 
	}
	if .Flags&protoiface.UnmarshalInitialized > 0 {
		return nil
	}
	return checkRequiredNotSet()
}