Source File
messageset.go
Belonging Package
google.golang.org/protobuf/internal/encoding/messageset
const (
FieldItem = protowire.Number(1)
FieldTypeID = protowire.Number(2)
FieldMessage = protowire.Number(3)
)
const ExtensionName = "message_set_extension"
func ( pref.MessageDescriptor) bool {
, := .(interface{ () bool })
return && .()
}
func ( pref.FieldDescriptor) bool {
if .Name() != ExtensionName {
return false
}
if .FullName().Parent() != .Message().FullName() {
return false
}
return IsMessageSet(.ContainingMessage())
}
func ( preg.ExtensionTypeResolver, pref.FullName) (pref.ExtensionType, error) {
:= .Append(ExtensionName)
, := .FindExtensionByName()
if != nil {
if == preg.NotFound {
return nil,
}
return nil, errors.Wrap(, "%q", )
}
if !IsMessageSetExtension(.TypeDescriptor()) {
return nil, preg.NotFound
}
return , nil
}
func ( []byte, bool, func( protowire.Number, []byte) error) error {
for len() > 0 {
, , := protowire.ConsumeTag()
if < 0 {
return protowire.ParseError()
}
= [:]
if != FieldItem || != protowire.StartGroupType {
:= protowire.ConsumeFieldValue(, , )
if < 0 {
return protowire.ParseError()
}
= [:]
continue
}
, , , := ConsumeFieldValue(, )
if != nil {
return
}
= [:]
if == 0 {
continue
}
if := (, ); != nil {
return
}
}
return nil
}
= protowire.AppendVarint(, 0)
}
return , , - len(), nil
case == FieldTypeID && == protowire.VarintType:
, := protowire.ConsumeVarint()
if < 0 {
return 0, nil, 0, protowire.ParseError()
}
= [:]
if < 1 || > math.MaxInt32 {
return 0, nil, 0, errors.New("invalid type_id in message set")
}
= protowire.Number()
case == FieldMessage && == protowire.BytesType:
, := protowire.ConsumeBytes()
if < 0 {
return 0, nil, 0, protowire.ParseError()
}
if == nil {
if {
= [::]
} else {
= [:len():len()]
}
:= protowire.ConsumeFieldValue(, , )
if < 0 {
return 0, nil, 0, protowire.ParseError()
}
= [:]
}
}
}
func ( []byte, protowire.Number) []byte {
= protowire.AppendTag(, FieldItem, protowire.StartGroupType)
= protowire.AppendTag(, FieldTypeID, protowire.VarintType)
= protowire.AppendVarint(, uint64())
return
}
func ( []byte) ( int) {
for len() > 0 {
, , := protowire.ConsumeTag()
if < 0 || != protowire.BytesType {
return 0
}
= [:]
_, = protowire.ConsumeBytes()
if < 0 {
return 0
}
= [:]
+= SizeField() + protowire.SizeTag(FieldMessage) +
}
return
}
func (, []byte) ([]byte, error) {
for len() > 0 {
, , := protowire.ConsumeTag()
if < 0 || != protowire.BytesType {
return nil, errors.New("invalid data in message set unknown fields")
}
= [:]
_, = protowire.ConsumeBytes()
if < 0 {
return nil, errors.New("invalid data in message set unknown fields")
}
= AppendFieldStart(, )
= protowire.AppendTag(, FieldMessage, protowire.BytesType)
= append(, [:]...)
= AppendFieldEnd()
= [:]
}
return , nil
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |