package impl
import (
preg
piface
)
var enableLazy int32 = func() int32 {
if os.Getenv("GOPROTODEBUG") == "nolazy" {
return 0
}
return 1
}()
func ( bool) {
if {
atomic.StoreInt32(&enableLazy, 1)
return
}
atomic.StoreInt32(&enableLazy, 0)
}
func () bool {
return atomic.LoadInt32(&enableLazy) != 0
}
func ( interface{}, protowire.Number) {
switch m := .(type) {
case *messageState:
.messageInfo().lazyUnmarshal(.pointer(), )
case *messageReflectWrapper:
.messageInfo().lazyUnmarshal(.pointer(), )
default:
panic(fmt.Sprintf("unsupported wrapper type %T", ))
}
}
func ( *MessageInfo) ( pointer, protoreflect.FieldNumber) {
var *coderFieldInfo
if int() < len(.denseCoderFields) {
= .denseCoderFields[]
} else {
= .coderFields[]
}
if == nil {
panic(fmt.Sprintf("lazyUnmarshal: field info for %v.%v", .Desc.FullName(), ))
}
:= *.Apply(.lazyOffset).LazyInfoPtr()
, , , , := .FindFieldInProto(uint32())
if ! && == nil {
panic(fmt.Sprintf("lazyUnmarshal: can't find field data for %v.%v", .Desc.FullName(), ))
}
:= pointerOfValue(reflect.New(.ft))
if != nil {
for , := range {
.unmarshalField(.Buffer()[.Start:.End], , , , .UnmarshalFlags())
}
} else {
.unmarshalField(.Buffer()[:], , , , .UnmarshalFlags())
}
.Apply(.offset).AtomicSetPointerIfNil(.Elem())
}
func ( *MessageInfo) ( []byte, pointer, *coderFieldInfo, *protolazy.XXX_lazyUnmarshalInfo, piface.UnmarshalInputFlags) error {
:= lazyUnmarshalOptions
.flags |=
for len() > 0 {
var uint64
if [0] < 0x80 {
= uint64([0])
= [1:]
} else if len() >= 2 && [1] < 128 {
= uint64([0]&0x7f) + uint64([1])<<7
= [2:]
} else {
var int
, = protowire.ConsumeVarint()
if < 0 {
return errors.New("invalid wire data")
}
= [:]
}
var protowire.Number
if := >> 3; < uint64(protowire.MinValidNumber) || > uint64(protowire.MaxValidNumber) {
return errors.New("invalid wire data")
} else {
= protowire.Number()
}
:= protowire.Type( & 7)
if == .num {
, := .funcs.unmarshal(, , , , )
if == nil {
= [.n:]
continue
}
if != errUnknown {
return
}
}
:= protowire.ConsumeFieldValue(, , )
if < 0 {
return errors.New("invalid wire data")
}
= [:]
}
return nil
}
func ( *MessageInfo) ( []byte, *coderFieldInfo, protowire.Type, unmarshalOptions) ( unmarshalOutput, ValidationStatus) {
:= .validation.mi
if == nil {
:= .Desc.Fields().ByNumber(.num)
if == nil {
return , ValidationUnknown
}
:= .Message().FullName()
, := preg.GlobalTypes.FindMessageByName()
if != nil {
return , ValidationUnknown
}
var bool
, = .(*MessageInfo)
if ! {
return , ValidationUnknown
}
}
.init()
switch .validation.typ {
case validationTypeMessage:
if != protowire.BytesType {
return , ValidationWrongWireType
}
, := protowire.ConsumeBytes()
if < 0 {
return , ValidationInvalid
}
, := .validate(, 0, )
.n =
return ,
case validationTypeGroup:
if != protowire.StartGroupType {
return , ValidationWrongWireType
}
, := .validate(, .num, )
return ,
default:
return , ValidationUnknown
}
}
func ( *MessageInfo) ( []byte, pointer, protowire.Number, unmarshalOptions) ( unmarshalOutput, error) {
:= true
var uint64
var **protolazy.XXX_lazyUnmarshalInfo
var presence
var []protolazy.IndexEntry
var protowire.Number
:= false
:= false
= .Apply(.presenceOffset).PresenceInfo()
= .Apply(.lazyOffset).LazyInfoPtr()
if !.AnyPresent(.presenceSize) {
if .CanBeLazy() {
= true
if * == nil {
* = &protolazy.XXX_lazyUnmarshalInfo{}
}
(*).SetUnmarshalFlags(.flags)
if !.AliasBuffer() {
= append([]byte{}, ...)
.flags |= piface.UnmarshalAliasBuffer
}
(*).SetBuffer()
}
}
type uint8
const (
= iota
)
var map[*coderFieldInfo]
var *map[int32]ExtensionField
:= len()
:= 0
for len() > 0 {
var uint64
if [0] < 0x80 {
= uint64([0])
= [1:]
} else if len() >= 2 && [1] < 128 {
= uint64([0]&0x7f) + uint64([1])<<7
= [2:]
} else {
var int
, = protowire.ConsumeVarint()
if < 0 {
return , errDecode
}
= [:]
}
var protowire.Number
if := >> 3; < uint64(protowire.MinValidNumber) || > uint64(protowire.MaxValidNumber) {
return , errors.New("invalid field number")
} else {
= protowire.Number()
}
:= protowire.Type( & 7)
if == protowire.EndGroupType {
if != {
return , errors.New("mismatching end group marker")
}
= 0
break
}
var *coderFieldInfo
if int() < len(.denseCoderFields) {
= .denseCoderFields[]
} else {
= .coderFields[]
}
var int
:= errUnknown
:= false
:
switch {
case != nil:
if .funcs.unmarshal == nil {
break
}
if .isLazy && {
switch {
case == nil || [] == :
, := .skipField(, , , )
switch {
case ValidationValid:
= nil
.SetPresentUnatomic(.presenceIndex, .presenceSize)
|= .validation.requiredBit
if !.initialized {
= false
}
= .n
break
case ValidationInvalid:
return , errors.New("invalid proto wire format")
case ValidationWrongWireType:
break
case ValidationUnknown:
if == nil {
= make(map[*coderFieldInfo])
}
if .Present(.presenceIndex) {
.ClearPresent(.presenceIndex)
[] =
= true
break
} else {
[] =
}
}
case [] == :
= true
break
default:
}
}
if .isLazy && ! && .Present(.presenceIndex) {
if .Apply(.offset).AtomicGetPointer().IsNil() {
.lazyUnmarshal(, .num)
}
}
var unmarshalOutput
, = .funcs.unmarshal(, .Apply(.offset), , , )
= .n
if != nil {
break
}
|= .validation.requiredBit
if .funcs.isInit != nil && !.initialized {
= false
}
if .presenceIndex != noPresence {
.SetPresentUnatomic(.presenceIndex, .presenceSize)
}
default:
if == nil && .extensionOffset.IsValid() {
= .Apply(.extensionOffset).Extensions()
if * == nil {
* = make(map[int32]ExtensionField)
}
}
if == nil {
break
}
var unmarshalOutput
, = .unmarshalExtension(, , , *, )
if != nil {
break
}
= .n
if !.initialized {
= false
}
}
if != nil {
if != errUnknown {
return ,
}
= protowire.ConsumeFieldValue(, , )
if < 0 {
return , errDecode
}
if ! && !.DiscardUnknown() && .unknownOffset.IsValid() {
:= .mutableUnknownBytes()
* = protowire.AppendTag(*, , )
* = append(*, [:]...)
}
}
= [:]
:= - len()
if && != nil && .isLazy {
if != {
= append(, protolazy.IndexEntry{
FieldNum: uint32(),
Start: uint32(),
End: uint32(),
})
} else {
:= len() - 1
[].End = uint32()
[].MultipleContiguous = true
}
}
if < {
= true
}
=
=
}
if != 0 {
return , errors.New("missing end group marker")
}
if != nil {
for , := range {
if != {
continue
}
= false
if * == nil {
* = &protolazy.XXX_lazyUnmarshalInfo{}
}
if := .unmarshalField((*).Buffer(), .Apply(.offset), , *, .flags); != nil {
return ,
}
.SetPresentUnatomic(.presenceIndex, .presenceSize)
}
}
if {
if {
sort.Slice(, func(, int) bool {
return [].FieldNum < [].FieldNum ||
([].FieldNum == [].FieldNum &&
[].Start < [].Start)
})
}
if * == nil {
* = &protolazy.XXX_lazyUnmarshalInfo{}
}
(*).SetIndex()
}
if .numRequiredFields > 0 && bits.OnesCount64() != int(.numRequiredFields) {
= false
}
if {
.initialized = true
}
.n = - len()
return , nil
}