id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
131,800 | golang/protobuf | ptypes/timestamp.go | validateTimestamp | func validateTimestamp(ts *tspb.Timestamp) error {
if ts == nil {
return errors.New("timestamp: nil Timestamp")
}
if ts.Seconds < minValidSeconds {
return fmt.Errorf("timestamp: %v before 0001-01-01", ts)
}
if ts.Seconds >= maxValidSeconds {
return fmt.Errorf("timestamp: %v after 10000-01-01", ts)
}
if ts.... | go | func validateTimestamp(ts *tspb.Timestamp) error {
if ts == nil {
return errors.New("timestamp: nil Timestamp")
}
if ts.Seconds < minValidSeconds {
return fmt.Errorf("timestamp: %v before 0001-01-01", ts)
}
if ts.Seconds >= maxValidSeconds {
return fmt.Errorf("timestamp: %v after 10000-01-01", ts)
}
if ts.... | [
"func",
"validateTimestamp",
"(",
"ts",
"*",
"tspb",
".",
"Timestamp",
")",
"error",
"{",
"if",
"ts",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"ts",
".",
"Seconds",
"<",
"minValidSeconds",
"{",
... | // validateTimestamp determines whether a Timestamp is valid.
// A valid timestamp represents a time in the range
// [0001-01-01, 10000-01-01) and has a Nanos field
// in the range [0, 1e9).
//
// If the Timestamp is valid, validateTimestamp returns nil.
// Otherwise, it returns an error that describes
// the problem.
... | [
"validateTimestamp",
"determines",
"whether",
"a",
"Timestamp",
"is",
"valid",
".",
"A",
"valid",
"timestamp",
"represents",
"a",
"time",
"in",
"the",
"range",
"[",
"0001",
"-",
"01",
"-",
"01",
"10000",
"-",
"01",
"-",
"01",
")",
"and",
"has",
"a",
"N... | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/ptypes/timestamp.go#L63-L77 |
131,801 | golang/protobuf | ptypes/timestamp.go | Timestamp | func Timestamp(ts *tspb.Timestamp) (time.Time, error) {
// Don't return the zero value on error, because corresponds to a valid
// timestamp. Instead return whatever time.Unix gives us.
var t time.Time
if ts == nil {
t = time.Unix(0, 0).UTC() // treat nil like the empty Timestamp
} else {
t = time.Unix(ts.Seco... | go | func Timestamp(ts *tspb.Timestamp) (time.Time, error) {
// Don't return the zero value on error, because corresponds to a valid
// timestamp. Instead return whatever time.Unix gives us.
var t time.Time
if ts == nil {
t = time.Unix(0, 0).UTC() // treat nil like the empty Timestamp
} else {
t = time.Unix(ts.Seco... | [
"func",
"Timestamp",
"(",
"ts",
"*",
"tspb",
".",
"Timestamp",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"// Don't return the zero value on error, because corresponds to a valid",
"// timestamp. Instead return whatever time.Unix gives us.",
"var",
"t",
"time",
... | // Timestamp converts a google.protobuf.Timestamp proto to a time.Time.
// It returns an error if the argument is invalid.
//
// Unlike most Go functions, if Timestamp returns an error, the first return value
// is not the zero time.Time. Instead, it is the value obtained from the
// time.Unix function when passed the ... | [
"Timestamp",
"converts",
"a",
"google",
".",
"protobuf",
".",
"Timestamp",
"proto",
"to",
"a",
"time",
".",
"Time",
".",
"It",
"returns",
"an",
"error",
"if",
"the",
"argument",
"is",
"invalid",
".",
"Unlike",
"most",
"Go",
"functions",
"if",
"Timestamp",
... | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/ptypes/timestamp.go#L90-L100 |
131,802 | golang/protobuf | ptypes/timestamp.go | TimestampNow | func TimestampNow() *tspb.Timestamp {
ts, err := TimestampProto(time.Now())
if err != nil {
panic("ptypes: time.Now() out of Timestamp range")
}
return ts
} | go | func TimestampNow() *tspb.Timestamp {
ts, err := TimestampProto(time.Now())
if err != nil {
panic("ptypes: time.Now() out of Timestamp range")
}
return ts
} | [
"func",
"TimestampNow",
"(",
")",
"*",
"tspb",
".",
"Timestamp",
"{",
"ts",
",",
"err",
":=",
"TimestampProto",
"(",
"time",
".",
"Now",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",... | // TimestampNow returns a google.protobuf.Timestamp for the current time. | [
"TimestampNow",
"returns",
"a",
"google",
".",
"protobuf",
".",
"Timestamp",
"for",
"the",
"current",
"time",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/ptypes/timestamp.go#L103-L109 |
131,803 | golang/protobuf | ptypes/timestamp.go | TimestampProto | func TimestampProto(t time.Time) (*tspb.Timestamp, error) {
ts := &tspb.Timestamp{
Seconds: t.Unix(),
Nanos: int32(t.Nanosecond()),
}
if err := validateTimestamp(ts); err != nil {
return nil, err
}
return ts, nil
} | go | func TimestampProto(t time.Time) (*tspb.Timestamp, error) {
ts := &tspb.Timestamp{
Seconds: t.Unix(),
Nanos: int32(t.Nanosecond()),
}
if err := validateTimestamp(ts); err != nil {
return nil, err
}
return ts, nil
} | [
"func",
"TimestampProto",
"(",
"t",
"time",
".",
"Time",
")",
"(",
"*",
"tspb",
".",
"Timestamp",
",",
"error",
")",
"{",
"ts",
":=",
"&",
"tspb",
".",
"Timestamp",
"{",
"Seconds",
":",
"t",
".",
"Unix",
"(",
")",
",",
"Nanos",
":",
"int32",
"(",... | // TimestampProto converts the time.Time to a google.protobuf.Timestamp proto.
// It returns an error if the resulting Timestamp is invalid. | [
"TimestampProto",
"converts",
"the",
"time",
".",
"Time",
"to",
"a",
"google",
".",
"protobuf",
".",
"Timestamp",
"proto",
".",
"It",
"returns",
"an",
"error",
"if",
"the",
"resulting",
"Timestamp",
"is",
"invalid",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/ptypes/timestamp.go#L113-L122 |
131,804 | golang/protobuf | ptypes/timestamp.go | TimestampString | func TimestampString(ts *tspb.Timestamp) string {
t, err := Timestamp(ts)
if err != nil {
return fmt.Sprintf("(%v)", err)
}
return t.Format(time.RFC3339Nano)
} | go | func TimestampString(ts *tspb.Timestamp) string {
t, err := Timestamp(ts)
if err != nil {
return fmt.Sprintf("(%v)", err)
}
return t.Format(time.RFC3339Nano)
} | [
"func",
"TimestampString",
"(",
"ts",
"*",
"tspb",
".",
"Timestamp",
")",
"string",
"{",
"t",
",",
"err",
":=",
"Timestamp",
"(",
"ts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"err",
")",
"... | // TimestampString returns the RFC 3339 string for valid Timestamps. For invalid
// Timestamps, it returns an error message in parentheses. | [
"TimestampString",
"returns",
"the",
"RFC",
"3339",
"string",
"for",
"valid",
"Timestamps",
".",
"For",
"invalid",
"Timestamps",
"it",
"returns",
"an",
"error",
"message",
"in",
"parentheses",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/ptypes/timestamp.go#L126-L132 |
131,805 | golang/protobuf | proto/table_unmarshal.go | Unmarshal | func (a *InternalMessageInfo) Unmarshal(msg Message, b []byte) error {
// Load the unmarshal information for this message type.
// The atomic load ensures memory consistency.
u := atomicLoadUnmarshalInfo(&a.unmarshal)
if u == nil {
// Slow path: find unmarshal info for msg, update a with it.
u = getUnmarshalInf... | go | func (a *InternalMessageInfo) Unmarshal(msg Message, b []byte) error {
// Load the unmarshal information for this message type.
// The atomic load ensures memory consistency.
u := atomicLoadUnmarshalInfo(&a.unmarshal)
if u == nil {
// Slow path: find unmarshal info for msg, update a with it.
u = getUnmarshalInf... | [
"func",
"(",
"a",
"*",
"InternalMessageInfo",
")",
"Unmarshal",
"(",
"msg",
"Message",
",",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"// Load the unmarshal information for this message type.",
"// The atomic load ensures memory consistency.",
"u",
":=",
"atomicLoadUnmars... | // Unmarshal is the entry point from the generated .pb.go files.
// This function is not intended to be used by non-generated code.
// This function is not subject to any compatibility guarantee.
// msg contains a pointer to a protocol buffer struct.
// b is the data to be unmarshaled into the protocol buffer.
// a is ... | [
"Unmarshal",
"is",
"the",
"entry",
"point",
"from",
"the",
"generated",
".",
"pb",
".",
"go",
"files",
".",
"This",
"function",
"is",
"not",
"intended",
"to",
"be",
"used",
"by",
"non",
"-",
"generated",
"code",
".",
"This",
"function",
"is",
"not",
"s... | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_unmarshal.go#L53-L65 |
131,806 | golang/protobuf | proto/table_unmarshal.go | fieldUnmarshaler | func fieldUnmarshaler(f *reflect.StructField) unmarshaler {
if f.Type.Kind() == reflect.Map {
return makeUnmarshalMap(f)
}
return typeUnmarshaler(f.Type, f.Tag.Get("protobuf"))
} | go | func fieldUnmarshaler(f *reflect.StructField) unmarshaler {
if f.Type.Kind() == reflect.Map {
return makeUnmarshalMap(f)
}
return typeUnmarshaler(f.Type, f.Tag.Get("protobuf"))
} | [
"func",
"fieldUnmarshaler",
"(",
"f",
"*",
"reflect",
".",
"StructField",
")",
"unmarshaler",
"{",
"if",
"f",
".",
"Type",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Map",
"{",
"return",
"makeUnmarshalMap",
"(",
"f",
")",
"\n",
"}",
"\n",
"return",
... | // fieldUnmarshaler returns an unmarshaler for the given field. | [
"fieldUnmarshaler",
"returns",
"an",
"unmarshaler",
"for",
"the",
"given",
"field",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_unmarshal.go#L450-L455 |
131,807 | golang/protobuf | proto/table_unmarshal.go | skipField | func skipField(b []byte, wire int) ([]byte, error) {
switch wire {
case WireVarint:
_, k := decodeVarint(b)
if k == 0 {
return b, io.ErrUnexpectedEOF
}
b = b[k:]
case WireFixed32:
if len(b) < 4 {
return b, io.ErrUnexpectedEOF
}
b = b[4:]
case WireFixed64:
if len(b) < 8 {
return b, io.ErrUne... | go | func skipField(b []byte, wire int) ([]byte, error) {
switch wire {
case WireVarint:
_, k := decodeVarint(b)
if k == 0 {
return b, io.ErrUnexpectedEOF
}
b = b[k:]
case WireFixed32:
if len(b) < 4 {
return b, io.ErrUnexpectedEOF
}
b = b[4:]
case WireFixed64:
if len(b) < 8 {
return b, io.ErrUne... | [
"func",
"skipField",
"(",
"b",
"[",
"]",
"byte",
",",
"wire",
"int",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"switch",
"wire",
"{",
"case",
"WireVarint",
":",
"_",
",",
"k",
":=",
"decodeVarint",
"(",
"b",
")",
"\n",
"if",
"k",
"=="... | // skipField skips past a field of type wire and returns the remaining bytes. | [
"skipField",
"skips",
"past",
"a",
"field",
"of",
"type",
"wire",
"and",
"returns",
"the",
"remaining",
"bytes",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_unmarshal.go#L1848-L1882 |
131,808 | golang/protobuf | proto/table_unmarshal.go | encodeVarint | func encodeVarint(b []byte, x uint64) []byte {
for x >= 1<<7 {
b = append(b, byte(x&0x7f|0x80))
x >>= 7
}
return append(b, byte(x))
} | go | func encodeVarint(b []byte, x uint64) []byte {
for x >= 1<<7 {
b = append(b, byte(x&0x7f|0x80))
x >>= 7
}
return append(b, byte(x))
} | [
"func",
"encodeVarint",
"(",
"b",
"[",
"]",
"byte",
",",
"x",
"uint64",
")",
"[",
"]",
"byte",
"{",
"for",
"x",
">=",
"1",
"<<",
"7",
"{",
"b",
"=",
"append",
"(",
"b",
",",
"byte",
"(",
"x",
"&",
"0x7f",
"|",
"0x80",
")",
")",
"\n",
"x",
... | // encodeVarint appends a varint-encoded integer to b and returns the result. | [
"encodeVarint",
"appends",
"a",
"varint",
"-",
"encoded",
"integer",
"to",
"b",
"and",
"returns",
"the",
"result",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_unmarshal.go#L1940-L1946 |
131,809 | golang/protobuf | proto/table_unmarshal.go | decodeVarint | func decodeVarint(b []byte) (uint64, int) {
var x, y uint64
if len(b) == 0 {
goto bad
}
x = uint64(b[0])
if x < 0x80 {
return x, 1
}
x -= 0x80
if len(b) <= 1 {
goto bad
}
y = uint64(b[1])
x += y << 7
if y < 0x80 {
return x, 2
}
x -= 0x80 << 7
if len(b) <= 2 {
goto bad
}
y = uint64(b[2])
x ... | go | func decodeVarint(b []byte) (uint64, int) {
var x, y uint64
if len(b) == 0 {
goto bad
}
x = uint64(b[0])
if x < 0x80 {
return x, 1
}
x -= 0x80
if len(b) <= 1 {
goto bad
}
y = uint64(b[1])
x += y << 7
if y < 0x80 {
return x, 2
}
x -= 0x80 << 7
if len(b) <= 2 {
goto bad
}
y = uint64(b[2])
x ... | [
"func",
"decodeVarint",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"uint64",
",",
"int",
")",
"{",
"var",
"x",
",",
"y",
"uint64",
"\n",
"if",
"len",
"(",
"b",
")",
"==",
"0",
"{",
"goto",
"bad",
"\n",
"}",
"\n",
"x",
"=",
"uint64",
"(",
"b",
"[... | // decodeVarint reads a varint-encoded integer from b.
// Returns the decoded integer and the number of bytes read.
// If there is an error, it returns 0,0. | [
"decodeVarint",
"reads",
"a",
"varint",
"-",
"encoded",
"integer",
"from",
"b",
".",
"Returns",
"the",
"decoded",
"integer",
"and",
"the",
"number",
"of",
"bytes",
"read",
".",
"If",
"there",
"is",
"an",
"error",
"it",
"returns",
"0",
"0",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_unmarshal.go#L1951-L2053 |
131,810 | golang/protobuf | ptypes/duration.go | Duration | func Duration(p *durpb.Duration) (time.Duration, error) {
if err := validateDuration(p); err != nil {
return 0, err
}
d := time.Duration(p.Seconds) * time.Second
if int64(d/time.Second) != p.Seconds {
return 0, fmt.Errorf("duration: %v is out of range for time.Duration", p)
}
if p.Nanos != 0 {
d += time.Dur... | go | func Duration(p *durpb.Duration) (time.Duration, error) {
if err := validateDuration(p); err != nil {
return 0, err
}
d := time.Duration(p.Seconds) * time.Second
if int64(d/time.Second) != p.Seconds {
return 0, fmt.Errorf("duration: %v is out of range for time.Duration", p)
}
if p.Nanos != 0 {
d += time.Dur... | [
"func",
"Duration",
"(",
"p",
"*",
"durpb",
".",
"Duration",
")",
"(",
"time",
".",
"Duration",
",",
"error",
")",
"{",
"if",
"err",
":=",
"validateDuration",
"(",
"p",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n"... | // Duration converts a durpb.Duration to a time.Duration. Duration
// returns an error if the durpb.Duration is invalid or is too large to be
// represented in a time.Duration. | [
"Duration",
"converts",
"a",
"durpb",
".",
"Duration",
"to",
"a",
"time",
".",
"Duration",
".",
"Duration",
"returns",
"an",
"error",
"if",
"the",
"durpb",
".",
"Duration",
"is",
"invalid",
"or",
"is",
"too",
"large",
"to",
"be",
"represented",
"in",
"a"... | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/ptypes/duration.go#L76-L91 |
131,811 | golang/protobuf | ptypes/duration.go | DurationProto | func DurationProto(d time.Duration) *durpb.Duration {
nanos := d.Nanoseconds()
secs := nanos / 1e9
nanos -= secs * 1e9
return &durpb.Duration{
Seconds: secs,
Nanos: int32(nanos),
}
} | go | func DurationProto(d time.Duration) *durpb.Duration {
nanos := d.Nanoseconds()
secs := nanos / 1e9
nanos -= secs * 1e9
return &durpb.Duration{
Seconds: secs,
Nanos: int32(nanos),
}
} | [
"func",
"DurationProto",
"(",
"d",
"time",
".",
"Duration",
")",
"*",
"durpb",
".",
"Duration",
"{",
"nanos",
":=",
"d",
".",
"Nanoseconds",
"(",
")",
"\n",
"secs",
":=",
"nanos",
"/",
"1e9",
"\n",
"nanos",
"-=",
"secs",
"*",
"1e9",
"\n",
"return",
... | // DurationProto converts a time.Duration to a durpb.Duration. | [
"DurationProto",
"converts",
"a",
"time",
".",
"Duration",
"to",
"a",
"durpb",
".",
"Duration",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/ptypes/duration.go#L94-L102 |
131,812 | golang/protobuf | proto/message_set.go | skipVarint | func skipVarint(buf []byte) []byte {
i := 0
for ; buf[i]&0x80 != 0; i++ {
}
return buf[i+1:]
} | go | func skipVarint(buf []byte) []byte {
i := 0
for ; buf[i]&0x80 != 0; i++ {
}
return buf[i+1:]
} | [
"func",
"skipVarint",
"(",
"buf",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"i",
":=",
"0",
"\n",
"for",
";",
"buf",
"[",
"i",
"]",
"&",
"0x80",
"!=",
"0",
";",
"i",
"++",
"{",
"}",
"\n",
"return",
"buf",
"[",
"i",
"+",
"1",
":",
"]",... | // Support for the message_set_wire_format message option. | [
"Support",
"for",
"the",
"message_set_wire_format",
"message",
"option",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/message_set.go#L135-L140 |
131,813 | golang/protobuf | proto/message_set.go | unmarshalMessageSet | func unmarshalMessageSet(buf []byte, exts interface{}) error {
var m map[int32]Extension
switch exts := exts.(type) {
case *XXX_InternalExtensions:
m = exts.extensionsWrite()
case map[int32]Extension:
m = exts
default:
return errors.New("proto: not an extension map")
}
ms := new(messageSet)
if err := Unm... | go | func unmarshalMessageSet(buf []byte, exts interface{}) error {
var m map[int32]Extension
switch exts := exts.(type) {
case *XXX_InternalExtensions:
m = exts.extensionsWrite()
case map[int32]Extension:
m = exts
default:
return errors.New("proto: not an extension map")
}
ms := new(messageSet)
if err := Unm... | [
"func",
"unmarshalMessageSet",
"(",
"buf",
"[",
"]",
"byte",
",",
"exts",
"interface",
"{",
"}",
")",
"error",
"{",
"var",
"m",
"map",
"[",
"int32",
"]",
"Extension",
"\n",
"switch",
"exts",
":=",
"exts",
".",
"(",
"type",
")",
"{",
"case",
"*",
"X... | // unmarshalMessageSet decodes the extension map encoded in buf in the message set wire format.
// It is called by Unmarshal methods on protocol buffer messages with the message_set_wire_format option. | [
"unmarshalMessageSet",
"decodes",
"the",
"extension",
"map",
"encoded",
"in",
"buf",
"in",
"the",
"message",
"set",
"wire",
"format",
".",
"It",
"is",
"called",
"by",
"Unmarshal",
"methods",
"on",
"protocol",
"buffer",
"messages",
"with",
"the",
"message_set_wir... | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/message_set.go#L144-L181 |
131,814 | golang/protobuf | proto/decode.go | DecodeVarint | func DecodeVarint(buf []byte) (x uint64, n int) {
for shift := uint(0); shift < 64; shift += 7 {
if n >= len(buf) {
return 0, 0
}
b := uint64(buf[n])
n++
x |= (b & 0x7F) << shift
if (b & 0x80) == 0 {
return x, n
}
}
// The number is too large to represent in a 64-bit value.
return 0, 0
} | go | func DecodeVarint(buf []byte) (x uint64, n int) {
for shift := uint(0); shift < 64; shift += 7 {
if n >= len(buf) {
return 0, 0
}
b := uint64(buf[n])
n++
x |= (b & 0x7F) << shift
if (b & 0x80) == 0 {
return x, n
}
}
// The number is too large to represent in a 64-bit value.
return 0, 0
} | [
"func",
"DecodeVarint",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"x",
"uint64",
",",
"n",
"int",
")",
"{",
"for",
"shift",
":=",
"uint",
"(",
"0",
")",
";",
"shift",
"<",
"64",
";",
"shift",
"+=",
"7",
"{",
"if",
"n",
">=",
"len",
"(",
"buf",
... | // DecodeVarint reads a varint-encoded integer from the slice.
// It returns the integer and the number of bytes consumed, or
// zero if there is not enough.
// This is the format for the
// int32, int64, uint32, uint64, bool, and enum
// protocol buffer types. | [
"DecodeVarint",
"reads",
"a",
"varint",
"-",
"encoded",
"integer",
"from",
"the",
"slice",
".",
"It",
"returns",
"the",
"integer",
"and",
"the",
"number",
"of",
"bytes",
"consumed",
"or",
"zero",
"if",
"there",
"is",
"not",
"enough",
".",
"This",
"is",
"... | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/decode.go#L57-L72 |
131,815 | golang/protobuf | proto/decode.go | DecodeVarint | func (p *Buffer) DecodeVarint() (x uint64, err error) {
i := p.index
buf := p.buf
if i >= len(buf) {
return 0, io.ErrUnexpectedEOF
} else if buf[i] < 0x80 {
p.index++
return uint64(buf[i]), nil
} else if len(buf)-i < 10 {
return p.decodeVarintSlow()
}
var b uint64
// we already checked the first byte
... | go | func (p *Buffer) DecodeVarint() (x uint64, err error) {
i := p.index
buf := p.buf
if i >= len(buf) {
return 0, io.ErrUnexpectedEOF
} else if buf[i] < 0x80 {
p.index++
return uint64(buf[i]), nil
} else if len(buf)-i < 10 {
return p.decodeVarintSlow()
}
var b uint64
// we already checked the first byte
... | [
"func",
"(",
"p",
"*",
"Buffer",
")",
"DecodeVarint",
"(",
")",
"(",
"x",
"uint64",
",",
"err",
"error",
")",
"{",
"i",
":=",
"p",
".",
"index",
"\n",
"buf",
":=",
"p",
".",
"buf",
"\n\n",
"if",
"i",
">=",
"len",
"(",
"buf",
")",
"{",
"return... | // DecodeVarint reads a varint-encoded integer from the Buffer.
// This is the format for the
// int32, int64, uint32, uint64, bool, and enum
// protocol buffer types. | [
"DecodeVarint",
"reads",
"a",
"varint",
"-",
"encoded",
"integer",
"from",
"the",
"Buffer",
".",
"This",
"is",
"the",
"format",
"for",
"the",
"int32",
"int64",
"uint32",
"uint64",
"bool",
"and",
"enum",
"protocol",
"buffer",
"types",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/decode.go#L101-L195 |
131,816 | golang/protobuf | proto/decode.go | DecodeFixed64 | func (p *Buffer) DecodeFixed64() (x uint64, err error) {
// x, err already 0
i := p.index + 8
if i < 0 || i > len(p.buf) {
err = io.ErrUnexpectedEOF
return
}
p.index = i
x = uint64(p.buf[i-8])
x |= uint64(p.buf[i-7]) << 8
x |= uint64(p.buf[i-6]) << 16
x |= uint64(p.buf[i-5]) << 24
x |= uint64(p.buf[i-4])... | go | func (p *Buffer) DecodeFixed64() (x uint64, err error) {
// x, err already 0
i := p.index + 8
if i < 0 || i > len(p.buf) {
err = io.ErrUnexpectedEOF
return
}
p.index = i
x = uint64(p.buf[i-8])
x |= uint64(p.buf[i-7]) << 8
x |= uint64(p.buf[i-6]) << 16
x |= uint64(p.buf[i-5]) << 24
x |= uint64(p.buf[i-4])... | [
"func",
"(",
"p",
"*",
"Buffer",
")",
"DecodeFixed64",
"(",
")",
"(",
"x",
"uint64",
",",
"err",
"error",
")",
"{",
"// x, err already 0",
"i",
":=",
"p",
".",
"index",
"+",
"8",
"\n",
"if",
"i",
"<",
"0",
"||",
"i",
">",
"len",
"(",
"p",
".",
... | // DecodeFixed64 reads a 64-bit integer from the Buffer.
// This is the format for the
// fixed64, sfixed64, and double protocol buffer types. | [
"DecodeFixed64",
"reads",
"a",
"64",
"-",
"bit",
"integer",
"from",
"the",
"Buffer",
".",
"This",
"is",
"the",
"format",
"for",
"the",
"fixed64",
"sfixed64",
"and",
"double",
"protocol",
"buffer",
"types",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/decode.go#L200-L218 |
131,817 | golang/protobuf | proto/decode.go | DecodeFixed32 | func (p *Buffer) DecodeFixed32() (x uint64, err error) {
// x, err already 0
i := p.index + 4
if i < 0 || i > len(p.buf) {
err = io.ErrUnexpectedEOF
return
}
p.index = i
x = uint64(p.buf[i-4])
x |= uint64(p.buf[i-3]) << 8
x |= uint64(p.buf[i-2]) << 16
x |= uint64(p.buf[i-1]) << 24
return
} | go | func (p *Buffer) DecodeFixed32() (x uint64, err error) {
// x, err already 0
i := p.index + 4
if i < 0 || i > len(p.buf) {
err = io.ErrUnexpectedEOF
return
}
p.index = i
x = uint64(p.buf[i-4])
x |= uint64(p.buf[i-3]) << 8
x |= uint64(p.buf[i-2]) << 16
x |= uint64(p.buf[i-1]) << 24
return
} | [
"func",
"(",
"p",
"*",
"Buffer",
")",
"DecodeFixed32",
"(",
")",
"(",
"x",
"uint64",
",",
"err",
"error",
")",
"{",
"// x, err already 0",
"i",
":=",
"p",
".",
"index",
"+",
"4",
"\n",
"if",
"i",
"<",
"0",
"||",
"i",
">",
"len",
"(",
"p",
".",
... | // DecodeFixed32 reads a 32-bit integer from the Buffer.
// This is the format for the
// fixed32, sfixed32, and float protocol buffer types. | [
"DecodeFixed32",
"reads",
"a",
"32",
"-",
"bit",
"integer",
"from",
"the",
"Buffer",
".",
"This",
"is",
"the",
"format",
"for",
"the",
"fixed32",
"sfixed32",
"and",
"float",
"protocol",
"buffer",
"types",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/decode.go#L223-L237 |
131,818 | golang/protobuf | proto/decode.go | DecodeZigzag64 | func (p *Buffer) DecodeZigzag64() (x uint64, err error) {
x, err = p.DecodeVarint()
if err != nil {
return
}
x = (x >> 1) ^ uint64((int64(x&1)<<63)>>63)
return
} | go | func (p *Buffer) DecodeZigzag64() (x uint64, err error) {
x, err = p.DecodeVarint()
if err != nil {
return
}
x = (x >> 1) ^ uint64((int64(x&1)<<63)>>63)
return
} | [
"func",
"(",
"p",
"*",
"Buffer",
")",
"DecodeZigzag64",
"(",
")",
"(",
"x",
"uint64",
",",
"err",
"error",
")",
"{",
"x",
",",
"err",
"=",
"p",
".",
"DecodeVarint",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"x",
... | // DecodeZigzag64 reads a zigzag-encoded 64-bit integer
// from the Buffer.
// This is the format used for the sint64 protocol buffer type. | [
"DecodeZigzag64",
"reads",
"a",
"zigzag",
"-",
"encoded",
"64",
"-",
"bit",
"integer",
"from",
"the",
"Buffer",
".",
"This",
"is",
"the",
"format",
"used",
"for",
"the",
"sint64",
"protocol",
"buffer",
"type",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/decode.go#L242-L249 |
131,819 | golang/protobuf | proto/decode.go | DecodeZigzag32 | func (p *Buffer) DecodeZigzag32() (x uint64, err error) {
x, err = p.DecodeVarint()
if err != nil {
return
}
x = uint64((uint32(x) >> 1) ^ uint32((int32(x&1)<<31)>>31))
return
} | go | func (p *Buffer) DecodeZigzag32() (x uint64, err error) {
x, err = p.DecodeVarint()
if err != nil {
return
}
x = uint64((uint32(x) >> 1) ^ uint32((int32(x&1)<<31)>>31))
return
} | [
"func",
"(",
"p",
"*",
"Buffer",
")",
"DecodeZigzag32",
"(",
")",
"(",
"x",
"uint64",
",",
"err",
"error",
")",
"{",
"x",
",",
"err",
"=",
"p",
".",
"DecodeVarint",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"x",
... | // DecodeZigzag32 reads a zigzag-encoded 32-bit integer
// from the Buffer.
// This is the format used for the sint32 protocol buffer type. | [
"DecodeZigzag32",
"reads",
"a",
"zigzag",
"-",
"encoded",
"32",
"-",
"bit",
"integer",
"from",
"the",
"Buffer",
".",
"This",
"is",
"the",
"format",
"used",
"for",
"the",
"sint32",
"protocol",
"buffer",
"type",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/decode.go#L254-L261 |
131,820 | golang/protobuf | proto/decode.go | DecodeRawBytes | func (p *Buffer) DecodeRawBytes(alloc bool) (buf []byte, err error) {
n, err := p.DecodeVarint()
if err != nil {
return nil, err
}
nb := int(n)
if nb < 0 {
return nil, fmt.Errorf("proto: bad byte length %d", nb)
}
end := p.index + nb
if end < p.index || end > len(p.buf) {
return nil, io.ErrUnexpectedEOF
... | go | func (p *Buffer) DecodeRawBytes(alloc bool) (buf []byte, err error) {
n, err := p.DecodeVarint()
if err != nil {
return nil, err
}
nb := int(n)
if nb < 0 {
return nil, fmt.Errorf("proto: bad byte length %d", nb)
}
end := p.index + nb
if end < p.index || end > len(p.buf) {
return nil, io.ErrUnexpectedEOF
... | [
"func",
"(",
"p",
"*",
"Buffer",
")",
"DecodeRawBytes",
"(",
"alloc",
"bool",
")",
"(",
"buf",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"n",
",",
"err",
":=",
"p",
".",
"DecodeVarint",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"ret... | // DecodeRawBytes reads a count-delimited byte buffer from the Buffer.
// This is the format used for the bytes protocol buffer
// type and for embedded messages. | [
"DecodeRawBytes",
"reads",
"a",
"count",
"-",
"delimited",
"byte",
"buffer",
"from",
"the",
"Buffer",
".",
"This",
"is",
"the",
"format",
"used",
"for",
"the",
"bytes",
"protocol",
"buffer",
"type",
"and",
"for",
"embedded",
"messages",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/decode.go#L266-L292 |
131,821 | golang/protobuf | proto/decode.go | DecodeStringBytes | func (p *Buffer) DecodeStringBytes() (s string, err error) {
buf, err := p.DecodeRawBytes(false)
if err != nil {
return
}
return string(buf), nil
} | go | func (p *Buffer) DecodeStringBytes() (s string, err error) {
buf, err := p.DecodeRawBytes(false)
if err != nil {
return
}
return string(buf), nil
} | [
"func",
"(",
"p",
"*",
"Buffer",
")",
"DecodeStringBytes",
"(",
")",
"(",
"s",
"string",
",",
"err",
"error",
")",
"{",
"buf",
",",
"err",
":=",
"p",
".",
"DecodeRawBytes",
"(",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"... | // DecodeStringBytes reads an encoded string from the Buffer.
// This is the format used for the proto2 string type. | [
"DecodeStringBytes",
"reads",
"an",
"encoded",
"string",
"from",
"the",
"Buffer",
".",
"This",
"is",
"the",
"format",
"used",
"for",
"the",
"proto2",
"string",
"type",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/decode.go#L296-L302 |
131,822 | golang/protobuf | proto/decode.go | Unmarshal | func Unmarshal(buf []byte, pb Message) error {
pb.Reset()
if u, ok := pb.(newUnmarshaler); ok {
return u.XXX_Unmarshal(buf)
}
if u, ok := pb.(Unmarshaler); ok {
return u.Unmarshal(buf)
}
return NewBuffer(buf).Unmarshal(pb)
} | go | func Unmarshal(buf []byte, pb Message) error {
pb.Reset()
if u, ok := pb.(newUnmarshaler); ok {
return u.XXX_Unmarshal(buf)
}
if u, ok := pb.(Unmarshaler); ok {
return u.Unmarshal(buf)
}
return NewBuffer(buf).Unmarshal(pb)
} | [
"func",
"Unmarshal",
"(",
"buf",
"[",
"]",
"byte",
",",
"pb",
"Message",
")",
"error",
"{",
"pb",
".",
"Reset",
"(",
")",
"\n",
"if",
"u",
",",
"ok",
":=",
"pb",
".",
"(",
"newUnmarshaler",
")",
";",
"ok",
"{",
"return",
"u",
".",
"XXX_Unmarshal"... | // Unmarshal parses the protocol buffer representation in buf and places the
// decoded result in pb. If the struct underlying pb does not match
// the data in buf, the results can be unpredictable.
//
// Unmarshal resets pb before starting to unmarshal, so any
// existing data in pb is always removed. Use UnmarshalMe... | [
"Unmarshal",
"parses",
"the",
"protocol",
"buffer",
"representation",
"in",
"buf",
"and",
"places",
"the",
"decoded",
"result",
"in",
"pb",
".",
"If",
"the",
"struct",
"underlying",
"pb",
"does",
"not",
"match",
"the",
"data",
"in",
"buf",
"the",
"results",
... | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/decode.go#L334-L343 |
131,823 | golang/protobuf | proto/decode.go | DecodeMessage | func (p *Buffer) DecodeMessage(pb Message) error {
enc, err := p.DecodeRawBytes(false)
if err != nil {
return err
}
return NewBuffer(enc).Unmarshal(pb)
} | go | func (p *Buffer) DecodeMessage(pb Message) error {
enc, err := p.DecodeRawBytes(false)
if err != nil {
return err
}
return NewBuffer(enc).Unmarshal(pb)
} | [
"func",
"(",
"p",
"*",
"Buffer",
")",
"DecodeMessage",
"(",
"pb",
"Message",
")",
"error",
"{",
"enc",
",",
"err",
":=",
"p",
".",
"DecodeRawBytes",
"(",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",... | // DecodeMessage reads a count-delimited message from the Buffer. | [
"DecodeMessage",
"reads",
"a",
"count",
"-",
"delimited",
"message",
"from",
"the",
"Buffer",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/decode.go#L368-L374 |
131,824 | golang/protobuf | proto/decode.go | DecodeGroup | func (p *Buffer) DecodeGroup(pb Message) error {
b := p.buf[p.index:]
x, y := findEndGroup(b)
if x < 0 {
return io.ErrUnexpectedEOF
}
err := Unmarshal(b[:x], pb)
p.index += y
return err
} | go | func (p *Buffer) DecodeGroup(pb Message) error {
b := p.buf[p.index:]
x, y := findEndGroup(b)
if x < 0 {
return io.ErrUnexpectedEOF
}
err := Unmarshal(b[:x], pb)
p.index += y
return err
} | [
"func",
"(",
"p",
"*",
"Buffer",
")",
"DecodeGroup",
"(",
"pb",
"Message",
")",
"error",
"{",
"b",
":=",
"p",
".",
"buf",
"[",
"p",
".",
"index",
":",
"]",
"\n",
"x",
",",
"y",
":=",
"findEndGroup",
"(",
"b",
")",
"\n",
"if",
"x",
"<",
"0",
... | // DecodeGroup reads a tag-delimited group from the Buffer.
// StartGroup tag is already consumed. This function consumes
// EndGroup tag. | [
"DecodeGroup",
"reads",
"a",
"tag",
"-",
"delimited",
"group",
"from",
"the",
"Buffer",
".",
"StartGroup",
"tag",
"is",
"already",
"consumed",
".",
"This",
"function",
"consumes",
"EndGroup",
"tag",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/decode.go#L379-L388 |
131,825 | golang/protobuf | proto/decode.go | Unmarshal | func (p *Buffer) Unmarshal(pb Message) error {
// If the object can unmarshal itself, let it.
if u, ok := pb.(newUnmarshaler); ok {
err := u.XXX_Unmarshal(p.buf[p.index:])
p.index = len(p.buf)
return err
}
if u, ok := pb.(Unmarshaler); ok {
// NOTE: The history of proto have unfortunately been inconsistent
... | go | func (p *Buffer) Unmarshal(pb Message) error {
// If the object can unmarshal itself, let it.
if u, ok := pb.(newUnmarshaler); ok {
err := u.XXX_Unmarshal(p.buf[p.index:])
p.index = len(p.buf)
return err
}
if u, ok := pb.(Unmarshaler); ok {
// NOTE: The history of proto have unfortunately been inconsistent
... | [
"func",
"(",
"p",
"*",
"Buffer",
")",
"Unmarshal",
"(",
"pb",
"Message",
")",
"error",
"{",
"// If the object can unmarshal itself, let it.",
"if",
"u",
",",
"ok",
":=",
"pb",
".",
"(",
"newUnmarshaler",
")",
";",
"ok",
"{",
"err",
":=",
"u",
".",
"XXX_U... | // Unmarshal parses the protocol buffer representation in the
// Buffer and places the decoded result in pb. If the struct
// underlying pb does not match the data in the buffer, the results can be
// unpredictable.
//
// Unlike proto.Unmarshal, this does not reset pb before starting to unmarshal. | [
"Unmarshal",
"parses",
"the",
"protocol",
"buffer",
"representation",
"in",
"the",
"Buffer",
"and",
"places",
"the",
"decoded",
"result",
"in",
"pb",
".",
"If",
"the",
"struct",
"underlying",
"pb",
"does",
"not",
"match",
"the",
"data",
"in",
"the",
"buffer"... | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/decode.go#L396-L427 |
131,826 | golang/protobuf | proto/text_parser.go | missingRequiredFieldError | func (p *textParser) missingRequiredFieldError(sv reflect.Value) *RequiredNotSetError {
st := sv.Type()
sprops := GetProperties(st)
for i := 0; i < st.NumField(); i++ {
if !isNil(sv.Field(i)) {
continue
}
props := sprops.Prop[i]
if props.Required {
return &RequiredNotSetError{fmt.Sprintf("%v.%v", st, ... | go | func (p *textParser) missingRequiredFieldError(sv reflect.Value) *RequiredNotSetError {
st := sv.Type()
sprops := GetProperties(st)
for i := 0; i < st.NumField(); i++ {
if !isNil(sv.Field(i)) {
continue
}
props := sprops.Prop[i]
if props.Required {
return &RequiredNotSetError{fmt.Sprintf("%v.%v", st, ... | [
"func",
"(",
"p",
"*",
"textParser",
")",
"missingRequiredFieldError",
"(",
"sv",
"reflect",
".",
"Value",
")",
"*",
"RequiredNotSetError",
"{",
"st",
":=",
"sv",
".",
"Type",
"(",
")",
"\n",
"sprops",
":=",
"GetProperties",
"(",
"st",
")",
"\n",
"for",
... | // Return a RequiredNotSetError indicating which required field was not set. | [
"Return",
"a",
"RequiredNotSetError",
"indicating",
"which",
"required",
"field",
"was",
"not",
"set",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/text_parser.go#L368-L382 |
131,827 | golang/protobuf | proto/text_parser.go | consumeExtName | func (p *textParser) consumeExtName() (string, error) {
tok := p.next()
if tok.err != nil {
return "", tok.err
}
// If extension name or type url is quoted, it's a single token.
if len(tok.value) > 2 && isQuote(tok.value[0]) && tok.value[len(tok.value)-1] == tok.value[0] {
name, err := unquoteC(tok.value[1:le... | go | func (p *textParser) consumeExtName() (string, error) {
tok := p.next()
if tok.err != nil {
return "", tok.err
}
// If extension name or type url is quoted, it's a single token.
if len(tok.value) > 2 && isQuote(tok.value[0]) && tok.value[len(tok.value)-1] == tok.value[0] {
name, err := unquoteC(tok.value[1:le... | [
"func",
"(",
"p",
"*",
"textParser",
")",
"consumeExtName",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"tok",
":=",
"p",
".",
"next",
"(",
")",
"\n",
"if",
"tok",
".",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"tok",
".",
"err",... | // consumeExtName consumes extension name or expanded Any type URL and the
// following ']'. It returns the name or URL consumed. | [
"consumeExtName",
"consumes",
"extension",
"name",
"or",
"expanded",
"Any",
"type",
"URL",
"and",
"the",
"following",
"]",
".",
"It",
"returns",
"the",
"name",
"or",
"URL",
"consumed",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/text_parser.go#L694-L722 |
131,828 | golang/protobuf | proto/text_parser.go | consumeOptionalSeparator | func (p *textParser) consumeOptionalSeparator() error {
tok := p.next()
if tok.err != nil {
return tok.err
}
if tok.value != ";" && tok.value != "," {
p.back()
}
return nil
} | go | func (p *textParser) consumeOptionalSeparator() error {
tok := p.next()
if tok.err != nil {
return tok.err
}
if tok.value != ";" && tok.value != "," {
p.back()
}
return nil
} | [
"func",
"(",
"p",
"*",
"textParser",
")",
"consumeOptionalSeparator",
"(",
")",
"error",
"{",
"tok",
":=",
"p",
".",
"next",
"(",
")",
"\n",
"if",
"tok",
".",
"err",
"!=",
"nil",
"{",
"return",
"tok",
".",
"err",
"\n",
"}",
"\n",
"if",
"tok",
"."... | // consumeOptionalSeparator consumes an optional semicolon or comma.
// It is used in readStruct to provide backward compatibility. | [
"consumeOptionalSeparator",
"consumes",
"an",
"optional",
"semicolon",
"or",
"comma",
".",
"It",
"is",
"used",
"in",
"readStruct",
"to",
"provide",
"backward",
"compatibility",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/text_parser.go#L726-L735 |
131,829 | golang/protobuf | proto/table_marshal.go | Size | func (a *InternalMessageInfo) Size(msg Message) int {
u := getMessageMarshalInfo(msg, a)
ptr := toPointer(&msg)
if ptr.isNil() {
// We get here if msg is a typed nil ((*SomeMessage)(nil)),
// so it satisfies the interface, and msg == nil wouldn't
// catch it. We don't want crash in this case.
return 0
}
re... | go | func (a *InternalMessageInfo) Size(msg Message) int {
u := getMessageMarshalInfo(msg, a)
ptr := toPointer(&msg)
if ptr.isNil() {
// We get here if msg is a typed nil ((*SomeMessage)(nil)),
// so it satisfies the interface, and msg == nil wouldn't
// catch it. We don't want crash in this case.
return 0
}
re... | [
"func",
"(",
"a",
"*",
"InternalMessageInfo",
")",
"Size",
"(",
"msg",
"Message",
")",
"int",
"{",
"u",
":=",
"getMessageMarshalInfo",
"(",
"msg",
",",
"a",
")",
"\n",
"ptr",
":=",
"toPointer",
"(",
"&",
"msg",
")",
"\n",
"if",
"ptr",
".",
"isNil",
... | // Size is the entry point from generated code,
// and should be ONLY called by generated code.
// It computes the size of encoded data of msg.
// a is a pointer to a place to store cached marshal info. | [
"Size",
"is",
"the",
"entry",
"point",
"from",
"generated",
"code",
"and",
"should",
"be",
"ONLY",
"called",
"by",
"generated",
"code",
".",
"It",
"computes",
"the",
"size",
"of",
"encoded",
"data",
"of",
"msg",
".",
"a",
"is",
"a",
"pointer",
"to",
"a... | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_marshal.go#L116-L126 |
131,830 | golang/protobuf | proto/table_marshal.go | Marshal | func (a *InternalMessageInfo) Marshal(b []byte, msg Message, deterministic bool) ([]byte, error) {
u := getMessageMarshalInfo(msg, a)
ptr := toPointer(&msg)
if ptr.isNil() {
// We get here if msg is a typed nil ((*SomeMessage)(nil)),
// so it satisfies the interface, and msg == nil wouldn't
// catch it. We don... | go | func (a *InternalMessageInfo) Marshal(b []byte, msg Message, deterministic bool) ([]byte, error) {
u := getMessageMarshalInfo(msg, a)
ptr := toPointer(&msg)
if ptr.isNil() {
// We get here if msg is a typed nil ((*SomeMessage)(nil)),
// so it satisfies the interface, and msg == nil wouldn't
// catch it. We don... | [
"func",
"(",
"a",
"*",
"InternalMessageInfo",
")",
"Marshal",
"(",
"b",
"[",
"]",
"byte",
",",
"msg",
"Message",
",",
"deterministic",
"bool",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"u",
":=",
"getMessageMarshalInfo",
"(",
"msg",
",",
"a... | // Marshal is the entry point from generated code,
// and should be ONLY called by generated code.
// It marshals msg to the end of b.
// a is a pointer to a place to store cached marshal info. | [
"Marshal",
"is",
"the",
"entry",
"point",
"from",
"generated",
"code",
"and",
"should",
"be",
"ONLY",
"called",
"by",
"generated",
"code",
".",
"It",
"marshals",
"msg",
"to",
"the",
"end",
"of",
"b",
".",
"a",
"is",
"a",
"pointer",
"to",
"a",
"place",
... | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_marshal.go#L132-L142 |
131,831 | golang/protobuf | proto/table_marshal.go | size | func (u *marshalInfo) size(ptr pointer) int {
if atomic.LoadInt32(&u.initialized) == 0 {
u.computeMarshalInfo()
}
// If the message can marshal itself, let it do it, for compatibility.
// NOTE: This is not efficient.
if u.hasmarshaler {
m := ptr.asPointerTo(u.typ).Interface().(Marshaler)
b, _ := m.Marshal()... | go | func (u *marshalInfo) size(ptr pointer) int {
if atomic.LoadInt32(&u.initialized) == 0 {
u.computeMarshalInfo()
}
// If the message can marshal itself, let it do it, for compatibility.
// NOTE: This is not efficient.
if u.hasmarshaler {
m := ptr.asPointerTo(u.typ).Interface().(Marshaler)
b, _ := m.Marshal()... | [
"func",
"(",
"u",
"*",
"marshalInfo",
")",
"size",
"(",
"ptr",
"pointer",
")",
"int",
"{",
"if",
"atomic",
".",
"LoadInt32",
"(",
"&",
"u",
".",
"initialized",
")",
"==",
"0",
"{",
"u",
".",
"computeMarshalInfo",
"(",
")",
"\n",
"}",
"\n\n",
"// If... | // size is the main function to compute the size of the encoded data of a message.
// ptr is the pointer to the message. | [
"size",
"is",
"the",
"main",
"function",
"to",
"compute",
"the",
"size",
"of",
"the",
"encoded",
"data",
"of",
"a",
"message",
".",
"ptr",
"is",
"the",
"pointer",
"to",
"the",
"message",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_marshal.go#L164-L206 |
131,832 | golang/protobuf | proto/table_marshal.go | computeMarshalInfo | func (u *marshalInfo) computeMarshalInfo() {
u.Lock()
defer u.Unlock()
if u.initialized != 0 { // non-atomic read is ok as it is protected by the lock
return
}
t := u.typ
u.unrecognized = invalidField
u.extensions = invalidField
u.v1extensions = invalidField
u.sizecache = invalidField
// If the message ca... | go | func (u *marshalInfo) computeMarshalInfo() {
u.Lock()
defer u.Unlock()
if u.initialized != 0 { // non-atomic read is ok as it is protected by the lock
return
}
t := u.typ
u.unrecognized = invalidField
u.extensions = invalidField
u.v1extensions = invalidField
u.sizecache = invalidField
// If the message ca... | [
"func",
"(",
"u",
"*",
"marshalInfo",
")",
"computeMarshalInfo",
"(",
")",
"{",
"u",
".",
"Lock",
"(",
")",
"\n",
"defer",
"u",
".",
"Unlock",
"(",
")",
"\n",
"if",
"u",
".",
"initialized",
"!=",
"0",
"{",
"// non-atomic read is ok as it is protected by th... | // computeMarshalInfo initializes the marshal info. | [
"computeMarshalInfo",
"initializes",
"the",
"marshal",
"info",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_marshal.go#L301-L387 |
131,833 | golang/protobuf | proto/table_marshal.go | getExtElemInfo | func (u *marshalInfo) getExtElemInfo(desc *ExtensionDesc) *marshalElemInfo {
// get from cache first
u.RLock()
e, ok := u.extElems[desc.Field]
u.RUnlock()
if ok {
return e
}
t := reflect.TypeOf(desc.ExtensionType) // pointer or slice to basic type or struct
tags := strings.Split(desc.Tag, ",")
tag, err := s... | go | func (u *marshalInfo) getExtElemInfo(desc *ExtensionDesc) *marshalElemInfo {
// get from cache first
u.RLock()
e, ok := u.extElems[desc.Field]
u.RUnlock()
if ok {
return e
}
t := reflect.TypeOf(desc.ExtensionType) // pointer or slice to basic type or struct
tags := strings.Split(desc.Tag, ",")
tag, err := s... | [
"func",
"(",
"u",
"*",
"marshalInfo",
")",
"getExtElemInfo",
"(",
"desc",
"*",
"ExtensionDesc",
")",
"*",
"marshalElemInfo",
"{",
"// get from cache first",
"u",
".",
"RLock",
"(",
")",
"\n",
"e",
",",
"ok",
":=",
"u",
".",
"extElems",
"[",
"desc",
".",
... | // getExtElemInfo returns the information to marshal an extension element.
// The info it returns is initialized. | [
"getExtElemInfo",
"returns",
"the",
"information",
"to",
"marshal",
"an",
"extension",
"element",
".",
"The",
"info",
"it",
"returns",
"is",
"initialized",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_marshal.go#L398-L440 |
131,834 | golang/protobuf | proto/table_marshal.go | computeMarshalFieldInfo | func (fi *marshalFieldInfo) computeMarshalFieldInfo(f *reflect.StructField) {
// parse protobuf tag of the field.
// tag has format of "bytes,49,opt,name=foo,def=hello!"
tags := strings.Split(f.Tag.Get("protobuf"), ",")
if tags[0] == "" {
return
}
tag, err := strconv.Atoi(tags[1])
if err != nil {
panic("tag ... | go | func (fi *marshalFieldInfo) computeMarshalFieldInfo(f *reflect.StructField) {
// parse protobuf tag of the field.
// tag has format of "bytes,49,opt,name=foo,def=hello!"
tags := strings.Split(f.Tag.Get("protobuf"), ",")
if tags[0] == "" {
return
}
tag, err := strconv.Atoi(tags[1])
if err != nil {
panic("tag ... | [
"func",
"(",
"fi",
"*",
"marshalFieldInfo",
")",
"computeMarshalFieldInfo",
"(",
"f",
"*",
"reflect",
".",
"StructField",
")",
"{",
"// parse protobuf tag of the field.",
"// tag has format of \"bytes,49,opt,name=foo,def=hello!\"",
"tags",
":=",
"strings",
".",
"Split",
"... | // computeMarshalFieldInfo fills up the information to marshal a field. | [
"computeMarshalFieldInfo",
"fills",
"up",
"the",
"information",
"to",
"marshal",
"a",
"field",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_marshal.go#L443-L460 |
131,835 | golang/protobuf | proto/table_marshal.go | wiretype | func wiretype(encoding string) uint64 {
switch encoding {
case "fixed32":
return WireFixed32
case "fixed64":
return WireFixed64
case "varint", "zigzag32", "zigzag64":
return WireVarint
case "bytes":
return WireBytes
case "group":
return WireStartGroup
}
panic("unknown wire type " + encoding)
} | go | func wiretype(encoding string) uint64 {
switch encoding {
case "fixed32":
return WireFixed32
case "fixed64":
return WireFixed64
case "varint", "zigzag32", "zigzag64":
return WireVarint
case "bytes":
return WireBytes
case "group":
return WireStartGroup
}
panic("unknown wire type " + encoding)
} | [
"func",
"wiretype",
"(",
"encoding",
"string",
")",
"uint64",
"{",
"switch",
"encoding",
"{",
"case",
"\"",
"\"",
":",
"return",
"WireFixed32",
"\n",
"case",
"\"",
"\"",
":",
"return",
"WireFixed64",
"\n",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\""... | // wiretype returns the wire encoding of the type. | [
"wiretype",
"returns",
"the",
"wire",
"encoding",
"of",
"the",
"type",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_marshal.go#L493-L507 |
131,836 | golang/protobuf | proto/table_marshal.go | setMarshaler | func (fi *marshalFieldInfo) setMarshaler(f *reflect.StructField, tags []string) {
switch f.Type.Kind() {
case reflect.Map:
// map field
fi.isPointer = true
fi.sizer, fi.marshaler = makeMapMarshaler(f)
return
case reflect.Ptr, reflect.Slice:
fi.isPointer = true
}
fi.sizer, fi.marshaler = typeMarshaler(f.T... | go | func (fi *marshalFieldInfo) setMarshaler(f *reflect.StructField, tags []string) {
switch f.Type.Kind() {
case reflect.Map:
// map field
fi.isPointer = true
fi.sizer, fi.marshaler = makeMapMarshaler(f)
return
case reflect.Ptr, reflect.Slice:
fi.isPointer = true
}
fi.sizer, fi.marshaler = typeMarshaler(f.T... | [
"func",
"(",
"fi",
"*",
"marshalFieldInfo",
")",
"setMarshaler",
"(",
"f",
"*",
"reflect",
".",
"StructField",
",",
"tags",
"[",
"]",
"string",
")",
"{",
"switch",
"f",
".",
"Type",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Map",
":",
"/... | // setMarshaler fills up the sizer and marshaler in the info of a field. | [
"setMarshaler",
"fills",
"up",
"the",
"sizer",
"and",
"marshaler",
"in",
"the",
"info",
"of",
"a",
"field",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_marshal.go#L517-L528 |
131,837 | golang/protobuf | proto/table_marshal.go | appendFixed32 | func appendFixed32(b []byte, v uint32) []byte {
b = append(b,
byte(v),
byte(v>>8),
byte(v>>16),
byte(v>>24))
return b
} | go | func appendFixed32(b []byte, v uint32) []byte {
b = append(b,
byte(v),
byte(v>>8),
byte(v>>16),
byte(v>>24))
return b
} | [
"func",
"appendFixed32",
"(",
"b",
"[",
"]",
"byte",
",",
"v",
"uint32",
")",
"[",
"]",
"byte",
"{",
"b",
"=",
"append",
"(",
"b",
",",
"byte",
"(",
"v",
")",
",",
"byte",
"(",
"v",
">>",
"8",
")",
",",
"byte",
"(",
"v",
">>",
"16",
")",
... | // appendFixed32 appends an encoded fixed32 to b. | [
"appendFixed32",
"appends",
"an",
"encoded",
"fixed32",
"to",
"b",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_marshal.go#L1290-L1297 |
131,838 | golang/protobuf | proto/table_marshal.go | appendFixed64 | func appendFixed64(b []byte, v uint64) []byte {
b = append(b,
byte(v),
byte(v>>8),
byte(v>>16),
byte(v>>24),
byte(v>>32),
byte(v>>40),
byte(v>>48),
byte(v>>56))
return b
} | go | func appendFixed64(b []byte, v uint64) []byte {
b = append(b,
byte(v),
byte(v>>8),
byte(v>>16),
byte(v>>24),
byte(v>>32),
byte(v>>40),
byte(v>>48),
byte(v>>56))
return b
} | [
"func",
"appendFixed64",
"(",
"b",
"[",
"]",
"byte",
",",
"v",
"uint64",
")",
"[",
"]",
"byte",
"{",
"b",
"=",
"append",
"(",
"b",
",",
"byte",
"(",
"v",
")",
",",
"byte",
"(",
"v",
">>",
"8",
")",
",",
"byte",
"(",
"v",
">>",
"16",
")",
... | // appendFixed64 appends an encoded fixed64 to b. | [
"appendFixed64",
"appends",
"an",
"encoded",
"fixed64",
"to",
"b",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_marshal.go#L1300-L1311 |
131,839 | golang/protobuf | proto/table_marshal.go | makeGroupMarshaler | func makeGroupMarshaler(u *marshalInfo) (sizer, marshaler) {
return func(ptr pointer, tagsize int) int {
p := ptr.getPointer()
if p.isNil() {
return 0
}
return u.size(p) + 2*tagsize
},
func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
p := ptr.getPointer()
if p... | go | func makeGroupMarshaler(u *marshalInfo) (sizer, marshaler) {
return func(ptr pointer, tagsize int) int {
p := ptr.getPointer()
if p.isNil() {
return 0
}
return u.size(p) + 2*tagsize
},
func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
p := ptr.getPointer()
if p... | [
"func",
"makeGroupMarshaler",
"(",
"u",
"*",
"marshalInfo",
")",
"(",
"sizer",
",",
"marshaler",
")",
"{",
"return",
"func",
"(",
"ptr",
"pointer",
",",
"tagsize",
"int",
")",
"int",
"{",
"p",
":=",
"ptr",
".",
"getPointer",
"(",
")",
"\n",
"if",
"p"... | // makeGroupMarshaler returns the sizer and marshaler for a group.
// u is the marshal info of the underlying message. | [
"makeGroupMarshaler",
"returns",
"the",
"sizer",
"and",
"marshaler",
"for",
"a",
"group",
".",
"u",
"is",
"the",
"marshal",
"info",
"of",
"the",
"underlying",
"message",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_marshal.go#L2158-L2177 |
131,840 | golang/protobuf | proto/table_marshal.go | makeGroupSliceMarshaler | func makeGroupSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
return func(ptr pointer, tagsize int) int {
s := ptr.getPointerSlice()
n := 0
for _, v := range s {
if v.isNil() {
continue
}
n += u.size(v) + 2*tagsize
}
return n
},
func(b []byte, ptr pointer, wiretag uint64, determ... | go | func makeGroupSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
return func(ptr pointer, tagsize int) int {
s := ptr.getPointerSlice()
n := 0
for _, v := range s {
if v.isNil() {
continue
}
n += u.size(v) + 2*tagsize
}
return n
},
func(b []byte, ptr pointer, wiretag uint64, determ... | [
"func",
"makeGroupSliceMarshaler",
"(",
"u",
"*",
"marshalInfo",
")",
"(",
"sizer",
",",
"marshaler",
")",
"{",
"return",
"func",
"(",
"ptr",
"pointer",
",",
"tagsize",
"int",
")",
"int",
"{",
"s",
":=",
"ptr",
".",
"getPointerSlice",
"(",
")",
"\n",
"... | // makeGroupSliceMarshaler returns the sizer and marshaler for a group slice.
// u is the marshal info of the underlying message. | [
"makeGroupSliceMarshaler",
"returns",
"the",
"sizer",
"and",
"marshaler",
"for",
"a",
"group",
"slice",
".",
"u",
"is",
"the",
"marshal",
"info",
"of",
"the",
"underlying",
"message",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_marshal.go#L2181-L2213 |
131,841 | golang/protobuf | proto/table_marshal.go | makeMessageMarshaler | func makeMessageMarshaler(u *marshalInfo) (sizer, marshaler) {
return func(ptr pointer, tagsize int) int {
p := ptr.getPointer()
if p.isNil() {
return 0
}
siz := u.size(p)
return siz + SizeVarint(uint64(siz)) + tagsize
},
func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, e... | go | func makeMessageMarshaler(u *marshalInfo) (sizer, marshaler) {
return func(ptr pointer, tagsize int) int {
p := ptr.getPointer()
if p.isNil() {
return 0
}
siz := u.size(p)
return siz + SizeVarint(uint64(siz)) + tagsize
},
func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, e... | [
"func",
"makeMessageMarshaler",
"(",
"u",
"*",
"marshalInfo",
")",
"(",
"sizer",
",",
"marshaler",
")",
"{",
"return",
"func",
"(",
"ptr",
"pointer",
",",
"tagsize",
"int",
")",
"int",
"{",
"p",
":=",
"ptr",
".",
"getPointer",
"(",
")",
"\n",
"if",
"... | // makeMessageMarshaler returns the sizer and marshaler for a message field.
// u is the marshal info of the message. | [
"makeMessageMarshaler",
"returns",
"the",
"sizer",
"and",
"marshaler",
"for",
"a",
"message",
"field",
".",
"u",
"is",
"the",
"marshal",
"info",
"of",
"the",
"message",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_marshal.go#L2217-L2236 |
131,842 | golang/protobuf | proto/table_marshal.go | makeOneOfMarshaler | func makeOneOfMarshaler(fi *marshalFieldInfo, f *reflect.StructField) (sizer, marshaler) {
// Oneof field is an interface. We need to get the actual data type on the fly.
t := f.Type
return func(ptr pointer, _ int) int {
p := ptr.getInterfacePointer()
if p.isNil() {
return 0
}
v := ptr.asPointerTo(t)... | go | func makeOneOfMarshaler(fi *marshalFieldInfo, f *reflect.StructField) (sizer, marshaler) {
// Oneof field is an interface. We need to get the actual data type on the fly.
t := f.Type
return func(ptr pointer, _ int) int {
p := ptr.getInterfacePointer()
if p.isNil() {
return 0
}
v := ptr.asPointerTo(t)... | [
"func",
"makeOneOfMarshaler",
"(",
"fi",
"*",
"marshalFieldInfo",
",",
"f",
"*",
"reflect",
".",
"StructField",
")",
"(",
"sizer",
",",
"marshaler",
")",
"{",
"// Oneof field is an interface. We need to get the actual data type on the fly.",
"t",
":=",
"f",
".",
"Type... | // makeOneOfMarshaler returns the sizer and marshaler for a oneof field.
// fi is the marshal info of the field.
// f is the pointer to the reflect data structure of the field. | [
"makeOneOfMarshaler",
"returns",
"the",
"sizer",
"and",
"marshaler",
"for",
"a",
"oneof",
"field",
".",
"fi",
"is",
"the",
"marshal",
"info",
"of",
"the",
"field",
".",
"f",
"is",
"the",
"pointer",
"to",
"the",
"reflect",
"data",
"structure",
"of",
"the",
... | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_marshal.go#L2362-L2388 |
131,843 | golang/protobuf | proto/table_marshal.go | sizeExtensions | func (u *marshalInfo) sizeExtensions(ext *XXX_InternalExtensions) int {
m, mu := ext.extensionsRead()
if m == nil {
return 0
}
mu.Lock()
n := 0
for _, e := range m {
if e.value == nil || e.desc == nil {
// Extension is only in its encoded form.
n += len(e.enc)
continue
}
// We don't skip extens... | go | func (u *marshalInfo) sizeExtensions(ext *XXX_InternalExtensions) int {
m, mu := ext.extensionsRead()
if m == nil {
return 0
}
mu.Lock()
n := 0
for _, e := range m {
if e.value == nil || e.desc == nil {
// Extension is only in its encoded form.
n += len(e.enc)
continue
}
// We don't skip extens... | [
"func",
"(",
"u",
"*",
"marshalInfo",
")",
"sizeExtensions",
"(",
"ext",
"*",
"XXX_InternalExtensions",
")",
"int",
"{",
"m",
",",
"mu",
":=",
"ext",
".",
"extensionsRead",
"(",
")",
"\n",
"if",
"m",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
... | // sizeExtensions computes the size of encoded data for a XXX_InternalExtensions field. | [
"sizeExtensions",
"computes",
"the",
"size",
"of",
"encoded",
"data",
"for",
"a",
"XXX_InternalExtensions",
"field",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_marshal.go#L2391-L2416 |
131,844 | golang/protobuf | proto/table_marshal.go | appendExtensions | func (u *marshalInfo) appendExtensions(b []byte, ext *XXX_InternalExtensions, deterministic bool) ([]byte, error) {
m, mu := ext.extensionsRead()
if m == nil {
return b, nil
}
mu.Lock()
defer mu.Unlock()
var err error
var nerr nonFatal
// Fast-path for common cases: zero or one extensions.
// Don't bother ... | go | func (u *marshalInfo) appendExtensions(b []byte, ext *XXX_InternalExtensions, deterministic bool) ([]byte, error) {
m, mu := ext.extensionsRead()
if m == nil {
return b, nil
}
mu.Lock()
defer mu.Unlock()
var err error
var nerr nonFatal
// Fast-path for common cases: zero or one extensions.
// Don't bother ... | [
"func",
"(",
"u",
"*",
"marshalInfo",
")",
"appendExtensions",
"(",
"b",
"[",
"]",
"byte",
",",
"ext",
"*",
"XXX_InternalExtensions",
",",
"deterministic",
"bool",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"m",
",",
"mu",
":=",
"ext",
".",
... | // appendExtensions marshals a XXX_InternalExtensions field to the end of byte slice b. | [
"appendExtensions",
"marshals",
"a",
"XXX_InternalExtensions",
"field",
"to",
"the",
"end",
"of",
"byte",
"slice",
"b",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_marshal.go#L2419-L2484 |
131,845 | golang/protobuf | proto/table_marshal.go | sizeV1Extensions | func (u *marshalInfo) sizeV1Extensions(m map[int32]Extension) int {
if m == nil {
return 0
}
n := 0
for _, e := range m {
if e.value == nil || e.desc == nil {
// Extension is only in its encoded form.
n += len(e.enc)
continue
}
// We don't skip extensions that have an encoded form set,
// becau... | go | func (u *marshalInfo) sizeV1Extensions(m map[int32]Extension) int {
if m == nil {
return 0
}
n := 0
for _, e := range m {
if e.value == nil || e.desc == nil {
// Extension is only in its encoded form.
n += len(e.enc)
continue
}
// We don't skip extensions that have an encoded form set,
// becau... | [
"func",
"(",
"u",
"*",
"marshalInfo",
")",
"sizeV1Extensions",
"(",
"m",
"map",
"[",
"int32",
"]",
"Extension",
")",
"int",
"{",
"if",
"m",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"n",
":=",
"0",
"\n",
"for",
"_",
",",
"e",
":=",
"r... | // sizeV1Extensions computes the size of encoded data for a V1-API extension field. | [
"sizeV1Extensions",
"computes",
"the",
"size",
"of",
"encoded",
"data",
"for",
"a",
"V1",
"-",
"API",
"extension",
"field",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_marshal.go#L2614-L2637 |
131,846 | golang/protobuf | proto/table_marshal.go | appendV1Extensions | func (u *marshalInfo) appendV1Extensions(b []byte, m map[int32]Extension, deterministic bool) ([]byte, error) {
if m == nil {
return b, nil
}
// Sort the keys to provide a deterministic encoding.
keys := make([]int, 0, len(m))
for k := range m {
keys = append(keys, int(k))
}
sort.Ints(keys)
var err error
... | go | func (u *marshalInfo) appendV1Extensions(b []byte, m map[int32]Extension, deterministic bool) ([]byte, error) {
if m == nil {
return b, nil
}
// Sort the keys to provide a deterministic encoding.
keys := make([]int, 0, len(m))
for k := range m {
keys = append(keys, int(k))
}
sort.Ints(keys)
var err error
... | [
"func",
"(",
"u",
"*",
"marshalInfo",
")",
"appendV1Extensions",
"(",
"b",
"[",
"]",
"byte",
",",
"m",
"map",
"[",
"int32",
"]",
"Extension",
",",
"deterministic",
"bool",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"m",
"==",
"nil",
... | // appendV1Extensions marshals a V1-API extension field to the end of byte slice b. | [
"appendV1Extensions",
"marshals",
"a",
"V1",
"-",
"API",
"extension",
"field",
"to",
"the",
"end",
"of",
"byte",
"slice",
"b",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_marshal.go#L2640-L2675 |
131,847 | golang/protobuf | proto/table_marshal.go | Size | func Size(pb Message) int {
if m, ok := pb.(newMarshaler); ok {
return m.XXX_Size()
}
if m, ok := pb.(Marshaler); ok {
// If the message can marshal itself, let it do it, for compatibility.
// NOTE: This is not efficient.
b, _ := m.Marshal()
return len(b)
}
// in case somehow we didn't generate the wrapp... | go | func Size(pb Message) int {
if m, ok := pb.(newMarshaler); ok {
return m.XXX_Size()
}
if m, ok := pb.(Marshaler); ok {
// If the message can marshal itself, let it do it, for compatibility.
// NOTE: This is not efficient.
b, _ := m.Marshal()
return len(b)
}
// in case somehow we didn't generate the wrapp... | [
"func",
"Size",
"(",
"pb",
"Message",
")",
"int",
"{",
"if",
"m",
",",
"ok",
":=",
"pb",
".",
"(",
"newMarshaler",
")",
";",
"ok",
"{",
"return",
"m",
".",
"XXX_Size",
"(",
")",
"\n",
"}",
"\n",
"if",
"m",
",",
"ok",
":=",
"pb",
".",
"(",
"... | // Size returns the encoded size of a protocol buffer message.
// This is the main entry point. | [
"Size",
"returns",
"the",
"encoded",
"size",
"of",
"a",
"protocol",
"buffer",
"message",
".",
"This",
"is",
"the",
"main",
"entry",
"point",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_marshal.go#L2690-L2706 |
131,848 | golang/protobuf | proto/table_marshal.go | Marshal | func Marshal(pb Message) ([]byte, error) {
if m, ok := pb.(newMarshaler); ok {
siz := m.XXX_Size()
b := make([]byte, 0, siz)
return m.XXX_Marshal(b, false)
}
if m, ok := pb.(Marshaler); ok {
// If the message can marshal itself, let it do it, for compatibility.
// NOTE: This is not efficient.
return m.Ma... | go | func Marshal(pb Message) ([]byte, error) {
if m, ok := pb.(newMarshaler); ok {
siz := m.XXX_Size()
b := make([]byte, 0, siz)
return m.XXX_Marshal(b, false)
}
if m, ok := pb.(Marshaler); ok {
// If the message can marshal itself, let it do it, for compatibility.
// NOTE: This is not efficient.
return m.Ma... | [
"func",
"Marshal",
"(",
"pb",
"Message",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"m",
",",
"ok",
":=",
"pb",
".",
"(",
"newMarshaler",
")",
";",
"ok",
"{",
"siz",
":=",
"m",
".",
"XXX_Size",
"(",
")",
"\n",
"b",
":=",
"make"... | // Marshal takes a protocol buffer message
// and encodes it into the wire format, returning the data.
// This is the main entry point. | [
"Marshal",
"takes",
"a",
"protocol",
"buffer",
"message",
"and",
"encodes",
"it",
"into",
"the",
"wire",
"format",
"returning",
"the",
"data",
".",
"This",
"is",
"the",
"main",
"entry",
"point",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_marshal.go#L2711-L2730 |
131,849 | golang/protobuf | proto/table_marshal.go | Marshal | func (p *Buffer) Marshal(pb Message) error {
var err error
if m, ok := pb.(newMarshaler); ok {
siz := m.XXX_Size()
p.grow(siz) // make sure buf has enough capacity
p.buf, err = m.XXX_Marshal(p.buf, p.deterministic)
return err
}
if m, ok := pb.(Marshaler); ok {
// If the message can marshal itself, let it ... | go | func (p *Buffer) Marshal(pb Message) error {
var err error
if m, ok := pb.(newMarshaler); ok {
siz := m.XXX_Size()
p.grow(siz) // make sure buf has enough capacity
p.buf, err = m.XXX_Marshal(p.buf, p.deterministic)
return err
}
if m, ok := pb.(Marshaler); ok {
// If the message can marshal itself, let it ... | [
"func",
"(",
"p",
"*",
"Buffer",
")",
"Marshal",
"(",
"pb",
"Message",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"if",
"m",
",",
"ok",
":=",
"pb",
".",
"(",
"newMarshaler",
")",
";",
"ok",
"{",
"siz",
":=",
"m",
".",
"XXX_Size",
"(",
")",... | // Marshal takes a protocol buffer message
// and encodes it into the wire format, writing the result to the
// Buffer.
// This is an alternative entry point. It is not necessary to use
// a Buffer for most applications. | [
"Marshal",
"takes",
"a",
"protocol",
"buffer",
"message",
"and",
"encodes",
"it",
"into",
"the",
"wire",
"format",
"writing",
"the",
"result",
"to",
"the",
"Buffer",
".",
"This",
"is",
"an",
"alternative",
"entry",
"point",
".",
"It",
"is",
"not",
"necessa... | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/table_marshal.go#L2737-L2761 |
131,850 | golang/protobuf | proto/equal.go | equalStruct | func equalStruct(v1, v2 reflect.Value) bool {
sprop := GetProperties(v1.Type())
for i := 0; i < v1.NumField(); i++ {
f := v1.Type().Field(i)
if strings.HasPrefix(f.Name, "XXX_") {
continue
}
f1, f2 := v1.Field(i), v2.Field(i)
if f.Type.Kind() == reflect.Ptr {
if n1, n2 := f1.IsNil(), f2.IsNil(); n1 &&... | go | func equalStruct(v1, v2 reflect.Value) bool {
sprop := GetProperties(v1.Type())
for i := 0; i < v1.NumField(); i++ {
f := v1.Type().Field(i)
if strings.HasPrefix(f.Name, "XXX_") {
continue
}
f1, f2 := v1.Field(i), v2.Field(i)
if f.Type.Kind() == reflect.Ptr {
if n1, n2 := f1.IsNil(), f2.IsNil(); n1 &&... | [
"func",
"equalStruct",
"(",
"v1",
",",
"v2",
"reflect",
".",
"Value",
")",
"bool",
"{",
"sprop",
":=",
"GetProperties",
"(",
"v1",
".",
"Type",
"(",
")",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"v1",
".",
"NumField",
"(",
")",
";",
"i"... | // v1 and v2 are known to have the same type. | [
"v1",
"and",
"v2",
"are",
"known",
"to",
"have",
"the",
"same",
"type",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/equal.go#L96-L141 |
131,851 | golang/protobuf | proto/equal.go | equalExtensions | func equalExtensions(base reflect.Type, x1, x2 XXX_InternalExtensions) bool {
em1, _ := x1.extensionsRead()
em2, _ := x2.extensionsRead()
return equalExtMap(base, em1, em2)
} | go | func equalExtensions(base reflect.Type, x1, x2 XXX_InternalExtensions) bool {
em1, _ := x1.extensionsRead()
em2, _ := x2.extensionsRead()
return equalExtMap(base, em1, em2)
} | [
"func",
"equalExtensions",
"(",
"base",
"reflect",
".",
"Type",
",",
"x1",
",",
"x2",
"XXX_InternalExtensions",
")",
"bool",
"{",
"em1",
",",
"_",
":=",
"x1",
".",
"extensionsRead",
"(",
")",
"\n",
"em2",
",",
"_",
":=",
"x2",
".",
"extensionsRead",
"(... | // base is the struct type that the extensions are based on.
// x1 and x2 are InternalExtensions. | [
"base",
"is",
"the",
"struct",
"type",
"that",
"the",
"extensions",
"are",
"based",
"on",
".",
"x1",
"and",
"x2",
"are",
"InternalExtensions",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/equal.go#L232-L236 |
131,852 | golang/protobuf | ptypes/any.go | AnyMessageName | func AnyMessageName(any *any.Any) (string, error) {
if any == nil {
return "", fmt.Errorf("message is nil")
}
slash := strings.LastIndex(any.TypeUrl, "/")
if slash < 0 {
return "", fmt.Errorf("message type url %q is invalid", any.TypeUrl)
}
return any.TypeUrl[slash+1:], nil
} | go | func AnyMessageName(any *any.Any) (string, error) {
if any == nil {
return "", fmt.Errorf("message is nil")
}
slash := strings.LastIndex(any.TypeUrl, "/")
if slash < 0 {
return "", fmt.Errorf("message type url %q is invalid", any.TypeUrl)
}
return any.TypeUrl[slash+1:], nil
} | [
"func",
"AnyMessageName",
"(",
"any",
"*",
"any",
".",
"Any",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"any",
"==",
"nil",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"slash",
":=",
"str... | // AnyMessageName returns the name of the message contained in a google.protobuf.Any message.
//
// Note that regular type assertions should be done using the Is
// function. AnyMessageName is provided for less common use cases like filtering a
// sequence of Any messages based on a set of allowed message type names. | [
"AnyMessageName",
"returns",
"the",
"name",
"of",
"the",
"message",
"contained",
"in",
"a",
"google",
".",
"protobuf",
".",
"Any",
"message",
".",
"Note",
"that",
"regular",
"type",
"assertions",
"should",
"be",
"done",
"using",
"the",
"Is",
"function",
".",... | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/ptypes/any.go#L53-L62 |
131,853 | golang/protobuf | ptypes/any.go | MarshalAny | func MarshalAny(pb proto.Message) (*any.Any, error) {
value, err := proto.Marshal(pb)
if err != nil {
return nil, err
}
return &any.Any{TypeUrl: googleApis + proto.MessageName(pb), Value: value}, nil
} | go | func MarshalAny(pb proto.Message) (*any.Any, error) {
value, err := proto.Marshal(pb)
if err != nil {
return nil, err
}
return &any.Any{TypeUrl: googleApis + proto.MessageName(pb), Value: value}, nil
} | [
"func",
"MarshalAny",
"(",
"pb",
"proto",
".",
"Message",
")",
"(",
"*",
"any",
".",
"Any",
",",
"error",
")",
"{",
"value",
",",
"err",
":=",
"proto",
".",
"Marshal",
"(",
"pb",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"... | // MarshalAny takes the protocol buffer and encodes it into google.protobuf.Any. | [
"MarshalAny",
"takes",
"the",
"protocol",
"buffer",
"and",
"encodes",
"it",
"into",
"google",
".",
"protobuf",
".",
"Any",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/ptypes/any.go#L65-L71 |
131,854 | golang/protobuf | ptypes/any.go | Empty | func Empty(any *any.Any) (proto.Message, error) {
aname, err := AnyMessageName(any)
if err != nil {
return nil, err
}
t := proto.MessageType(aname)
if t == nil {
return nil, fmt.Errorf("any: message type %q isn't linked in", aname)
}
return reflect.New(t.Elem()).Interface().(proto.Message), nil
} | go | func Empty(any *any.Any) (proto.Message, error) {
aname, err := AnyMessageName(any)
if err != nil {
return nil, err
}
t := proto.MessageType(aname)
if t == nil {
return nil, fmt.Errorf("any: message type %q isn't linked in", aname)
}
return reflect.New(t.Elem()).Interface().(proto.Message), nil
} | [
"func",
"Empty",
"(",
"any",
"*",
"any",
".",
"Any",
")",
"(",
"proto",
".",
"Message",
",",
"error",
")",
"{",
"aname",
",",
"err",
":=",
"AnyMessageName",
"(",
"any",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
... | // Empty returns a new proto.Message of the type specified in a
// google.protobuf.Any message. It returns an error if corresponding message
// type isn't linked in. | [
"Empty",
"returns",
"a",
"new",
"proto",
".",
"Message",
"of",
"the",
"type",
"specified",
"in",
"a",
"google",
".",
"protobuf",
".",
"Any",
"message",
".",
"It",
"returns",
"an",
"error",
"if",
"corresponding",
"message",
"type",
"isn",
"t",
"linked",
"... | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/ptypes/any.go#L89-L100 |
131,855 | golang/protobuf | ptypes/any.go | Is | func Is(any *any.Any, pb proto.Message) bool {
// The following is equivalent to AnyMessageName(any) == proto.MessageName(pb),
// but it avoids scanning TypeUrl for the slash.
if any == nil {
return false
}
name := proto.MessageName(pb)
prefix := len(any.TypeUrl) - len(name)
return prefix >= 1 && any.TypeUrl[p... | go | func Is(any *any.Any, pb proto.Message) bool {
// The following is equivalent to AnyMessageName(any) == proto.MessageName(pb),
// but it avoids scanning TypeUrl for the slash.
if any == nil {
return false
}
name := proto.MessageName(pb)
prefix := len(any.TypeUrl) - len(name)
return prefix >= 1 && any.TypeUrl[p... | [
"func",
"Is",
"(",
"any",
"*",
"any",
".",
"Any",
",",
"pb",
"proto",
".",
"Message",
")",
"bool",
"{",
"// The following is equivalent to AnyMessageName(any) == proto.MessageName(pb),",
"// but it avoids scanning TypeUrl for the slash.",
"if",
"any",
"==",
"nil",
"{",
... | // Is returns true if any value contains a given message type. | [
"Is",
"returns",
"true",
"if",
"any",
"value",
"contains",
"a",
"given",
"message",
"type",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/ptypes/any.go#L132-L141 |
131,856 | golang/protobuf | proto/lib.go | isNonFatal | func isNonFatal(err error) bool {
if re, ok := err.(interface{ RequiredNotSet() bool }); ok && re.RequiredNotSet() {
return true
}
if re, ok := err.(interface{ InvalidUTF8() bool }); ok && re.InvalidUTF8() {
return true
}
return false
} | go | func isNonFatal(err error) bool {
if re, ok := err.(interface{ RequiredNotSet() bool }); ok && re.RequiredNotSet() {
return true
}
if re, ok := err.(interface{ InvalidUTF8() bool }); ok && re.InvalidUTF8() {
return true
}
return false
} | [
"func",
"isNonFatal",
"(",
"err",
"error",
")",
"bool",
"{",
"if",
"re",
",",
"ok",
":=",
"err",
".",
"(",
"interface",
"{",
"RequiredNotSet",
"(",
")",
"bool",
"}",
")",
";",
"ok",
"&&",
"re",
".",
"RequiredNotSet",
"(",
")",
"{",
"return",
"true"... | // isNonFatal reports whether the error is either a RequiredNotSet error
// or a InvalidUTF8 error. | [
"isNonFatal",
"reports",
"whether",
"the",
"error",
"is",
"either",
"a",
"RequiredNotSet",
"error",
"or",
"a",
"InvalidUTF8",
"error",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/lib.go#L310-L318 |
131,857 | golang/protobuf | proto/lib.go | Merge | func (nf *nonFatal) Merge(err error) (ok bool) {
if err == nil {
return true // not an error
}
if !isNonFatal(err) {
return false // fatal error
}
if nf.E == nil {
nf.E = err // store first instance of non-fatal error
}
return true
} | go | func (nf *nonFatal) Merge(err error) (ok bool) {
if err == nil {
return true // not an error
}
if !isNonFatal(err) {
return false // fatal error
}
if nf.E == nil {
nf.E = err // store first instance of non-fatal error
}
return true
} | [
"func",
"(",
"nf",
"*",
"nonFatal",
")",
"Merge",
"(",
"err",
"error",
")",
"(",
"ok",
"bool",
")",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"true",
"// not an error",
"\n",
"}",
"\n",
"if",
"!",
"isNonFatal",
"(",
"err",
")",
"{",
"return",
... | // Merge merges err into nf and reports whether it was successful.
// Otherwise it returns false for any fatal non-nil errors. | [
"Merge",
"merges",
"err",
"into",
"nf",
"and",
"reports",
"whether",
"it",
"was",
"successful",
".",
"Otherwise",
"it",
"returns",
"false",
"for",
"any",
"fatal",
"non",
"-",
"nil",
"errors",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/lib.go#L324-L335 |
131,858 | golang/protobuf | proto/lib.go | SetBuf | func (p *Buffer) SetBuf(s []byte) {
p.buf = s
p.index = 0
} | go | func (p *Buffer) SetBuf(s []byte) {
p.buf = s
p.index = 0
} | [
"func",
"(",
"p",
"*",
"Buffer",
")",
"SetBuf",
"(",
"s",
"[",
"]",
"byte",
")",
"{",
"p",
".",
"buf",
"=",
"s",
"\n",
"p",
".",
"index",
"=",
"0",
"\n",
"}"
] | // SetBuf replaces the internal buffer with the slice,
// ready for unmarshaling the contents of the slice. | [
"SetBuf",
"replaces",
"the",
"internal",
"buffer",
"with",
"the",
"slice",
"ready",
"for",
"unmarshaling",
"the",
"contents",
"of",
"the",
"slice",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/lib.go#L370-L373 |
131,859 | golang/protobuf | proto/lib.go | Int | func Int(v int) *int32 {
p := new(int32)
*p = int32(v)
return p
} | go | func Int(v int) *int32 {
p := new(int32)
*p = int32(v)
return p
} | [
"func",
"Int",
"(",
"v",
"int",
")",
"*",
"int32",
"{",
"p",
":=",
"new",
"(",
"int32",
")",
"\n",
"*",
"p",
"=",
"int32",
"(",
"v",
")",
"\n",
"return",
"p",
"\n",
"}"
] | // Int is a helper routine that allocates a new int32 value
// to store v and returns a pointer to it, but unlike Int32
// its argument value is an int. | [
"Int",
"is",
"a",
"helper",
"routine",
"that",
"allocates",
"a",
"new",
"int32",
"value",
"to",
"store",
"v",
"and",
"returns",
"a",
"pointer",
"to",
"it",
"but",
"unlike",
"Int32",
"its",
"argument",
"value",
"is",
"an",
"int",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/lib.go#L421-L425 |
131,860 | golang/protobuf | proto/lib.go | EnumName | func EnumName(m map[int32]string, v int32) string {
s, ok := m[v]
if ok {
return s
}
return strconv.Itoa(int(v))
} | go | func EnumName(m map[int32]string, v int32) string {
s, ok := m[v]
if ok {
return s
}
return strconv.Itoa(int(v))
} | [
"func",
"EnumName",
"(",
"m",
"map",
"[",
"int32",
"]",
"string",
",",
"v",
"int32",
")",
"string",
"{",
"s",
",",
"ok",
":=",
"m",
"[",
"v",
"]",
"\n",
"if",
"ok",
"{",
"return",
"s",
"\n",
"}",
"\n",
"return",
"strconv",
".",
"Itoa",
"(",
"... | // EnumName is a helper function to simplify printing protocol buffer enums
// by name. Given an enum map and a value, it returns a useful string. | [
"EnumName",
"is",
"a",
"helper",
"function",
"to",
"simplify",
"printing",
"protocol",
"buffer",
"enums",
"by",
"name",
".",
"Given",
"an",
"enum",
"map",
"and",
"a",
"value",
"it",
"returns",
"a",
"useful",
"string",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/lib.go#L465-L471 |
131,861 | golang/protobuf | proto/lib.go | UnmarshalJSONEnum | func UnmarshalJSONEnum(m map[string]int32, data []byte, enumName string) (int32, error) {
if data[0] == '"' {
// New style: enums are strings.
var repr string
if err := json.Unmarshal(data, &repr); err != nil {
return -1, err
}
val, ok := m[repr]
if !ok {
return 0, fmt.Errorf("unrecognized enum %s va... | go | func UnmarshalJSONEnum(m map[string]int32, data []byte, enumName string) (int32, error) {
if data[0] == '"' {
// New style: enums are strings.
var repr string
if err := json.Unmarshal(data, &repr); err != nil {
return -1, err
}
val, ok := m[repr]
if !ok {
return 0, fmt.Errorf("unrecognized enum %s va... | [
"func",
"UnmarshalJSONEnum",
"(",
"m",
"map",
"[",
"string",
"]",
"int32",
",",
"data",
"[",
"]",
"byte",
",",
"enumName",
"string",
")",
"(",
"int32",
",",
"error",
")",
"{",
"if",
"data",
"[",
"0",
"]",
"==",
"'\"'",
"{",
"// New style: enums are str... | // UnmarshalJSONEnum is a helper function to simplify recovering enum int values
// from their JSON-encoded representation. Given a map from the enum's symbolic
// names to its int values, and a byte buffer containing the JSON-encoded
// value, it returns an int32 that can be cast to the enum type by the caller.
//
// ... | [
"UnmarshalJSONEnum",
"is",
"a",
"helper",
"function",
"to",
"simplify",
"recovering",
"enum",
"int",
"values",
"from",
"their",
"JSON",
"-",
"encoded",
"representation",
".",
"Given",
"a",
"map",
"from",
"the",
"enum",
"s",
"symbolic",
"names",
"to",
"its",
... | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/lib.go#L479-L498 |
131,862 | golang/protobuf | proto/lib.go | DebugPrint | func (p *Buffer) DebugPrint(s string, b []byte) {
var u uint64
obuf := p.buf
index := p.index
p.buf = b
p.index = 0
depth := 0
fmt.Printf("\n--- %s ---\n", s)
out:
for {
for i := 0; i < depth; i++ {
fmt.Print(" ")
}
index := p.index
if index == len(p.buf) {
break
}
op, err := p.DecodeVar... | go | func (p *Buffer) DebugPrint(s string, b []byte) {
var u uint64
obuf := p.buf
index := p.index
p.buf = b
p.index = 0
depth := 0
fmt.Printf("\n--- %s ---\n", s)
out:
for {
for i := 0; i < depth; i++ {
fmt.Print(" ")
}
index := p.index
if index == len(p.buf) {
break
}
op, err := p.DecodeVar... | [
"func",
"(",
"p",
"*",
"Buffer",
")",
"DebugPrint",
"(",
"s",
"string",
",",
"b",
"[",
"]",
"byte",
")",
"{",
"var",
"u",
"uint64",
"\n\n",
"obuf",
":=",
"p",
".",
"buf",
"\n",
"index",
":=",
"p",
".",
"index",
"\n",
"p",
".",
"buf",
"=",
"b"... | // DebugPrint dumps the encoded data in b in a debugging format with a header
// including the string s. Used in testing but made available for general debugging. | [
"DebugPrint",
"dumps",
"the",
"encoded",
"data",
"in",
"b",
"in",
"a",
"debugging",
"format",
"with",
"a",
"header",
"including",
"the",
"string",
"s",
".",
"Used",
"in",
"testing",
"but",
"made",
"available",
"for",
"general",
"debugging",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/lib.go#L502-L602 |
131,863 | golang/protobuf | proto/lib.go | mapKeys | func mapKeys(vs []reflect.Value) sort.Interface {
s := mapKeySorter{vs: vs}
// Type specialization per https://developers.google.com/protocol-buffers/docs/proto#maps.
if len(vs) == 0 {
return s
}
switch vs[0].Kind() {
case reflect.Int32, reflect.Int64:
s.less = func(a, b reflect.Value) bool { return a.Int() ... | go | func mapKeys(vs []reflect.Value) sort.Interface {
s := mapKeySorter{vs: vs}
// Type specialization per https://developers.google.com/protocol-buffers/docs/proto#maps.
if len(vs) == 0 {
return s
}
switch vs[0].Kind() {
case reflect.Int32, reflect.Int64:
s.less = func(a, b reflect.Value) bool { return a.Int() ... | [
"func",
"mapKeys",
"(",
"vs",
"[",
"]",
"reflect",
".",
"Value",
")",
"sort",
".",
"Interface",
"{",
"s",
":=",
"mapKeySorter",
"{",
"vs",
":",
"vs",
"}",
"\n\n",
"// Type specialization per https://developers.google.com/protocol-buffers/docs/proto#maps.",
"if",
"le... | // mapKeys returns a sort.Interface to be used for sorting the map keys.
// Map fields may have key types of non-float scalars, strings and enums. | [
"mapKeys",
"returns",
"a",
"sort",
".",
"Interface",
"to",
"be",
"used",
"for",
"sorting",
"the",
"map",
"keys",
".",
"Map",
"fields",
"may",
"have",
"key",
"types",
"of",
"non",
"-",
"float",
"scalars",
"strings",
"and",
"enums",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/lib.go#L892-L913 |
131,864 | golang/protobuf | proto/lib.go | isProto3Zero | func isProto3Zero(v reflect.Value) bool {
switch v.Kind() {
case reflect.Bool:
return !v.Bool()
case reflect.Int32, reflect.Int64:
return v.Int() == 0
case reflect.Uint32, reflect.Uint64:
return v.Uint() == 0
case reflect.Float32, reflect.Float64:
return v.Float() == 0
case reflect.String:
return v.Stri... | go | func isProto3Zero(v reflect.Value) bool {
switch v.Kind() {
case reflect.Bool:
return !v.Bool()
case reflect.Int32, reflect.Int64:
return v.Int() == 0
case reflect.Uint32, reflect.Uint64:
return v.Uint() == 0
case reflect.Float32, reflect.Float64:
return v.Float() == 0
case reflect.String:
return v.Stri... | [
"func",
"isProto3Zero",
"(",
"v",
"reflect",
".",
"Value",
")",
"bool",
"{",
"switch",
"v",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Bool",
":",
"return",
"!",
"v",
".",
"Bool",
"(",
")",
"\n",
"case",
"reflect",
".",
"Int32",
",",
"r... | // isProto3Zero reports whether v is a zero proto3 value. | [
"isProto3Zero",
"reports",
"whether",
"v",
"is",
"a",
"zero",
"proto3",
"value",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/proto/lib.go#L927-L941 |
131,865 | golang/protobuf | protoc-gen-go/generator/generator.go | integerValueAsString | func (e *EnumDescriptor) integerValueAsString(name string) string {
for _, c := range e.Value {
if c.GetName() == name {
return fmt.Sprint(c.GetNumber())
}
}
log.Fatal("cannot find value for enum constant")
return ""
} | go | func (e *EnumDescriptor) integerValueAsString(name string) string {
for _, c := range e.Value {
if c.GetName() == name {
return fmt.Sprint(c.GetNumber())
}
}
log.Fatal("cannot find value for enum constant")
return ""
} | [
"func",
"(",
"e",
"*",
"EnumDescriptor",
")",
"integerValueAsString",
"(",
"name",
"string",
")",
"string",
"{",
"for",
"_",
",",
"c",
":=",
"range",
"e",
".",
"Value",
"{",
"if",
"c",
".",
"GetName",
"(",
")",
"==",
"name",
"{",
"return",
"fmt",
"... | // The integer value of the named constant in this enumerated type. | [
"The",
"integer",
"value",
"of",
"the",
"named",
"constant",
"in",
"this",
"enumerated",
"type",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L204-L212 |
131,866 | golang/protobuf | protoc-gen-go/generator/generator.go | DescName | func (e *ExtensionDescriptor) DescName() string {
// The full type name.
typeName := e.TypeName()
// Each scope of the extension is individually CamelCased, and all are joined with "_" with an "E_" prefix.
for i, s := range typeName {
typeName[i] = CamelCase(s)
}
return "E_" + strings.Join(typeName, "_")
} | go | func (e *ExtensionDescriptor) DescName() string {
// The full type name.
typeName := e.TypeName()
// Each scope of the extension is individually CamelCased, and all are joined with "_" with an "E_" prefix.
for i, s := range typeName {
typeName[i] = CamelCase(s)
}
return "E_" + strings.Join(typeName, "_")
} | [
"func",
"(",
"e",
"*",
"ExtensionDescriptor",
")",
"DescName",
"(",
")",
"string",
"{",
"// The full type name.",
"typeName",
":=",
"e",
".",
"TypeName",
"(",
")",
"\n",
"// Each scope of the extension is individually CamelCased, and all are joined with \"_\" with an \"E_\" p... | // DescName returns the variable name used for the generated descriptor. | [
"DescName",
"returns",
"the",
"variable",
"name",
"used",
"for",
"the",
"generated",
"descriptor",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L239-L247 |
131,867 | golang/protobuf | protoc-gen-go/generator/generator.go | VarName | func (d *FileDescriptor) VarName() string {
h := sha256.Sum256([]byte(d.GetName()))
return fmt.Sprintf("fileDescriptor_%s", hex.EncodeToString(h[:8]))
} | go | func (d *FileDescriptor) VarName() string {
h := sha256.Sum256([]byte(d.GetName()))
return fmt.Sprintf("fileDescriptor_%s", hex.EncodeToString(h[:8]))
} | [
"func",
"(",
"d",
"*",
"FileDescriptor",
")",
"VarName",
"(",
")",
"string",
"{",
"h",
":=",
"sha256",
".",
"Sum256",
"(",
"[",
"]",
"byte",
"(",
"d",
".",
"GetName",
"(",
")",
")",
")",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
"... | // VarName is the variable name we'll use in the generated code to refer
// to the compressed bytes of this descriptor. It is not exported, so
// it is only valid inside the generated package. | [
"VarName",
"is",
"the",
"variable",
"name",
"we",
"ll",
"use",
"in",
"the",
"generated",
"code",
"to",
"refer",
"to",
"the",
"compressed",
"bytes",
"of",
"this",
"descriptor",
".",
"It",
"is",
"not",
"exported",
"so",
"it",
"is",
"only",
"valid",
"inside... | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L284-L287 |
131,868 | golang/protobuf | protoc-gen-go/generator/generator.go | goFileName | func (d *FileDescriptor) goFileName(pathType pathType) string {
name := *d.Name
if ext := path.Ext(name); ext == ".proto" || ext == ".protodevel" {
name = name[:len(name)-len(ext)]
}
name += ".pb.go"
if pathType == pathTypeSourceRelative {
return name
}
// Does the file have a "go_package" option?
// If i... | go | func (d *FileDescriptor) goFileName(pathType pathType) string {
name := *d.Name
if ext := path.Ext(name); ext == ".proto" || ext == ".protodevel" {
name = name[:len(name)-len(ext)]
}
name += ".pb.go"
if pathType == pathTypeSourceRelative {
return name
}
// Does the file have a "go_package" option?
// If i... | [
"func",
"(",
"d",
"*",
"FileDescriptor",
")",
"goFileName",
"(",
"pathType",
"pathType",
")",
"string",
"{",
"name",
":=",
"*",
"d",
".",
"Name",
"\n",
"if",
"ext",
":=",
"path",
".",
"Ext",
"(",
"name",
")",
";",
"ext",
"==",
"\"",
"\"",
"||",
"... | // goFileName returns the output name for the generated Go file. | [
"goFileName",
"returns",
"the",
"output",
"name",
"for",
"the",
"generated",
"Go",
"file",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L312-L333 |
131,869 | golang/protobuf | protoc-gen-go/generator/generator.go | Error | func (g *Generator) Error(err error, msgs ...string) {
s := strings.Join(msgs, " ") + ":" + err.Error()
log.Print("protoc-gen-go: error:", s)
os.Exit(1)
} | go | func (g *Generator) Error(err error, msgs ...string) {
s := strings.Join(msgs, " ") + ":" + err.Error()
log.Print("protoc-gen-go: error:", s)
os.Exit(1)
} | [
"func",
"(",
"g",
"*",
"Generator",
")",
"Error",
"(",
"err",
"error",
",",
"msgs",
"...",
"string",
")",
"{",
"s",
":=",
"strings",
".",
"Join",
"(",
"msgs",
",",
"\"",
"\"",
")",
"+",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
"\n",
"l... | // Error reports a problem, including an error, and exits the program. | [
"Error",
"reports",
"a",
"problem",
"including",
"an",
"error",
"and",
"exits",
"the",
"program",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L450-L454 |
131,870 | golang/protobuf | protoc-gen-go/generator/generator.go | Fail | func (g *Generator) Fail(msgs ...string) {
s := strings.Join(msgs, " ")
log.Print("protoc-gen-go: error:", s)
os.Exit(1)
} | go | func (g *Generator) Fail(msgs ...string) {
s := strings.Join(msgs, " ")
log.Print("protoc-gen-go: error:", s)
os.Exit(1)
} | [
"func",
"(",
"g",
"*",
"Generator",
")",
"Fail",
"(",
"msgs",
"...",
"string",
")",
"{",
"s",
":=",
"strings",
".",
"Join",
"(",
"msgs",
",",
"\"",
"\"",
")",
"\n",
"log",
".",
"Print",
"(",
"\"",
"\"",
",",
"s",
")",
"\n",
"os",
".",
"Exit",... | // Fail reports a problem and exits the program. | [
"Fail",
"reports",
"a",
"problem",
"and",
"exits",
"the",
"program",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L457-L461 |
131,871 | golang/protobuf | protoc-gen-go/generator/generator.go | GoPackageName | func (g *Generator) GoPackageName(importPath GoImportPath) GoPackageName {
if name, ok := g.packageNames[importPath]; ok {
return name
}
name := cleanPackageName(baseName(string(importPath)))
for i, orig := 1, name; g.usedPackageNames[name] || isGoPredeclaredIdentifier[string(name)]; i++ {
name = orig + GoPacka... | go | func (g *Generator) GoPackageName(importPath GoImportPath) GoPackageName {
if name, ok := g.packageNames[importPath]; ok {
return name
}
name := cleanPackageName(baseName(string(importPath)))
for i, orig := 1, name; g.usedPackageNames[name] || isGoPredeclaredIdentifier[string(name)]; i++ {
name = orig + GoPacka... | [
"func",
"(",
"g",
"*",
"Generator",
")",
"GoPackageName",
"(",
"importPath",
"GoImportPath",
")",
"GoPackageName",
"{",
"if",
"name",
",",
"ok",
":=",
"g",
".",
"packageNames",
"[",
"importPath",
"]",
";",
"ok",
"{",
"return",
"name",
"\n",
"}",
"\n",
... | // GoPackageName returns the name used for a package. | [
"GoPackageName",
"returns",
"the",
"name",
"used",
"for",
"a",
"package",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L533-L544 |
131,872 | golang/protobuf | protoc-gen-go/generator/generator.go | AddImport | func (g *Generator) AddImport(importPath GoImportPath) GoPackageName {
g.addedImports[importPath] = true
return g.GoPackageName(importPath)
} | go | func (g *Generator) AddImport(importPath GoImportPath) GoPackageName {
g.addedImports[importPath] = true
return g.GoPackageName(importPath)
} | [
"func",
"(",
"g",
"*",
"Generator",
")",
"AddImport",
"(",
"importPath",
"GoImportPath",
")",
"GoPackageName",
"{",
"g",
".",
"addedImports",
"[",
"importPath",
"]",
"=",
"true",
"\n",
"return",
"g",
".",
"GoPackageName",
"(",
"importPath",
")",
"\n",
"}"
... | // AddImport adds a package to the generated file's import section.
// It returns the name used for the package. | [
"AddImport",
"adds",
"a",
"package",
"to",
"the",
"generated",
"file",
"s",
"import",
"section",
".",
"It",
"returns",
"the",
"name",
"used",
"for",
"the",
"package",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L548-L551 |
131,873 | golang/protobuf | protoc-gen-go/generator/generator.go | RegisterUniquePackageName | func RegisterUniquePackageName(pkg string, f *FileDescriptor) string {
name := cleanPackageName(pkg)
for i, orig := 1, name; globalPackageNames[name]; i++ {
name = orig + GoPackageName(strconv.Itoa(i))
}
globalPackageNames[name] = true
return string(name)
} | go | func RegisterUniquePackageName(pkg string, f *FileDescriptor) string {
name := cleanPackageName(pkg)
for i, orig := 1, name; globalPackageNames[name]; i++ {
name = orig + GoPackageName(strconv.Itoa(i))
}
globalPackageNames[name] = true
return string(name)
} | [
"func",
"RegisterUniquePackageName",
"(",
"pkg",
"string",
",",
"f",
"*",
"FileDescriptor",
")",
"string",
"{",
"name",
":=",
"cleanPackageName",
"(",
"pkg",
")",
"\n",
"for",
"i",
",",
"orig",
":=",
"1",
",",
"name",
";",
"globalPackageNames",
"[",
"name"... | // Create and remember a guaranteed unique package name. Pkg is the candidate name.
// The FileDescriptor parameter is unused. | [
"Create",
"and",
"remember",
"a",
"guaranteed",
"unique",
"package",
"name",
".",
"Pkg",
"is",
"the",
"candidate",
"name",
".",
"The",
"FileDescriptor",
"parameter",
"is",
"unused",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L561-L568 |
131,874 | golang/protobuf | protoc-gen-go/generator/generator.go | buildNestedDescriptors | func (g *Generator) buildNestedDescriptors(descs []*Descriptor) {
for _, desc := range descs {
if len(desc.NestedType) != 0 {
for _, nest := range descs {
if nest.parent == desc {
desc.nested = append(desc.nested, nest)
}
}
if len(desc.nested) != len(desc.NestedType) {
g.Fail("internal erro... | go | func (g *Generator) buildNestedDescriptors(descs []*Descriptor) {
for _, desc := range descs {
if len(desc.NestedType) != 0 {
for _, nest := range descs {
if nest.parent == desc {
desc.nested = append(desc.nested, nest)
}
}
if len(desc.nested) != len(desc.NestedType) {
g.Fail("internal erro... | [
"func",
"(",
"g",
"*",
"Generator",
")",
"buildNestedDescriptors",
"(",
"descs",
"[",
"]",
"*",
"Descriptor",
")",
"{",
"for",
"_",
",",
"desc",
":=",
"range",
"descs",
"{",
"if",
"len",
"(",
"desc",
".",
"NestedType",
")",
"!=",
"0",
"{",
"for",
"... | // Scan the descriptors in this file. For each one, build the slice of nested descriptors | [
"Scan",
"the",
"descriptors",
"in",
"this",
"file",
".",
"For",
"each",
"one",
"build",
"the",
"slice",
"of",
"nested",
"descriptors"
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L784-L797 |
131,875 | golang/protobuf | protoc-gen-go/generator/generator.go | BuildTypeNameMap | func (g *Generator) BuildTypeNameMap() {
g.typeNameToObject = make(map[string]Object)
for _, f := range g.allFiles {
// The names in this loop are defined by the proto world, not us, so the
// package name may be empty. If so, the dotted package name of X will
// be ".X"; otherwise it will be ".pkg.X".
dotte... | go | func (g *Generator) BuildTypeNameMap() {
g.typeNameToObject = make(map[string]Object)
for _, f := range g.allFiles {
// The names in this loop are defined by the proto world, not us, so the
// package name may be empty. If so, the dotted package name of X will
// be ".X"; otherwise it will be ".pkg.X".
dotte... | [
"func",
"(",
"g",
"*",
"Generator",
")",
"BuildTypeNameMap",
"(",
")",
"{",
"g",
".",
"typeNameToObject",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"Object",
")",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"g",
".",
"allFiles",
"{",
"// The names ... | // BuildTypeNameMap builds the map from fully qualified type names to objects.
// The key names for the map come from the input data, which puts a period at the beginning.
// It should be called after SetPackageNames and before GenerateAllFiles. | [
"BuildTypeNameMap",
"builds",
"the",
"map",
"from",
"fully",
"qualified",
"type",
"names",
"to",
"objects",
".",
"The",
"key",
"names",
"for",
"the",
"map",
"come",
"from",
"the",
"input",
"data",
"which",
"puts",
"a",
"period",
"at",
"the",
"beginning",
"... | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L948-L967 |
131,876 | golang/protobuf | protoc-gen-go/generator/generator.go | Annotate | func Annotate(file *FileDescriptor, path string, atoms ...interface{}) *AnnotatedAtoms {
return &AnnotatedAtoms{source: *file.Name, path: path, atoms: atoms}
} | go | func Annotate(file *FileDescriptor, path string, atoms ...interface{}) *AnnotatedAtoms {
return &AnnotatedAtoms{source: *file.Name, path: path, atoms: atoms}
} | [
"func",
"Annotate",
"(",
"file",
"*",
"FileDescriptor",
",",
"path",
"string",
",",
"atoms",
"...",
"interface",
"{",
"}",
")",
"*",
"AnnotatedAtoms",
"{",
"return",
"&",
"AnnotatedAtoms",
"{",
"source",
":",
"*",
"file",
".",
"Name",
",",
"path",
":",
... | // Annotate records the file name and proto AST path of a list of atoms
// so that a later call to P can emit a link from each atom to its origin. | [
"Annotate",
"records",
"the",
"file",
"name",
"and",
"proto",
"AST",
"path",
"of",
"a",
"list",
"of",
"atoms",
"so",
"that",
"a",
"later",
"call",
"to",
"P",
"can",
"emit",
"a",
"link",
"from",
"each",
"atom",
"to",
"its",
"origin",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L988-L990 |
131,877 | golang/protobuf | protoc-gen-go/generator/generator.go | addInitf | func (g *Generator) addInitf(stmt string, a ...interface{}) {
g.init = append(g.init, fmt.Sprintf(stmt, a...))
} | go | func (g *Generator) addInitf(stmt string, a ...interface{}) {
g.init = append(g.init, fmt.Sprintf(stmt, a...))
} | [
"func",
"(",
"g",
"*",
"Generator",
")",
"addInitf",
"(",
"stmt",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"{",
"g",
".",
"init",
"=",
"append",
"(",
"g",
".",
"init",
",",
"fmt",
".",
"Sprintf",
"(",
"stmt",
",",
"a",
"...",
")",... | // addInitf stores the given statement to be printed inside the file's init function.
// The statement is given as a format specifier and arguments. | [
"addInitf",
"stores",
"the",
"given",
"statement",
"to",
"be",
"printed",
"inside",
"the",
"file",
"s",
"init",
"function",
".",
"The",
"statement",
"is",
"given",
"as",
"a",
"format",
"specifier",
"and",
"arguments",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L1064-L1066 |
131,878 | golang/protobuf | protoc-gen-go/generator/generator.go | Out | func (g *Generator) Out() {
if len(g.indent) > 0 {
g.indent = g.indent[1:]
}
} | go | func (g *Generator) Out() {
if len(g.indent) > 0 {
g.indent = g.indent[1:]
}
} | [
"func",
"(",
"g",
"*",
"Generator",
")",
"Out",
"(",
")",
"{",
"if",
"len",
"(",
"g",
".",
"indent",
")",
">",
"0",
"{",
"g",
".",
"indent",
"=",
"g",
".",
"indent",
"[",
"1",
":",
"]",
"\n",
"}",
"\n",
"}"
] | // Out unindents the output one tab stop. | [
"Out",
"unindents",
"the",
"output",
"one",
"tab",
"stop",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L1072-L1076 |
131,879 | golang/protobuf | protoc-gen-go/generator/generator.go | GenerateAllFiles | func (g *Generator) GenerateAllFiles() {
// Initialize the plugins
for _, p := range plugins {
p.Init(g)
}
// Generate the output. The generator runs for every file, even the files
// that we don't generate output for, so that we can collate the full list
// of exported symbols to support public imports.
genFi... | go | func (g *Generator) GenerateAllFiles() {
// Initialize the plugins
for _, p := range plugins {
p.Init(g)
}
// Generate the output. The generator runs for every file, even the files
// that we don't generate output for, so that we can collate the full list
// of exported symbols to support public imports.
genFi... | [
"func",
"(",
"g",
"*",
"Generator",
")",
"GenerateAllFiles",
"(",
")",
"{",
"// Initialize the plugins",
"for",
"_",
",",
"p",
":=",
"range",
"plugins",
"{",
"p",
".",
"Init",
"(",
"g",
")",
"\n",
"}",
"\n",
"// Generate the output. The generator runs for ever... | // GenerateAllFiles generates the output for all the files we're outputting. | [
"GenerateAllFiles",
"generates",
"the",
"output",
"for",
"all",
"the",
"files",
"we",
"re",
"outputting",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L1079-L1113 |
131,880 | golang/protobuf | protoc-gen-go/generator/generator.go | runPlugins | func (g *Generator) runPlugins(file *FileDescriptor) {
for _, p := range plugins {
p.Generate(file)
}
} | go | func (g *Generator) runPlugins(file *FileDescriptor) {
for _, p := range plugins {
p.Generate(file)
}
} | [
"func",
"(",
"g",
"*",
"Generator",
")",
"runPlugins",
"(",
"file",
"*",
"FileDescriptor",
")",
"{",
"for",
"_",
",",
"p",
":=",
"range",
"plugins",
"{",
"p",
".",
"Generate",
"(",
"file",
")",
"\n",
"}",
"\n",
"}"
] | // Run all the plugins associated with the file. | [
"Run",
"all",
"the",
"plugins",
"associated",
"with",
"the",
"file",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L1116-L1120 |
131,881 | golang/protobuf | protoc-gen-go/generator/generator.go | makeComments | func (g *Generator) makeComments(path string) (string, bool) {
loc, ok := g.file.comments[path]
if !ok {
return "", false
}
w := new(bytes.Buffer)
nl := ""
for _, line := range strings.Split(strings.TrimSuffix(loc.GetLeadingComments(), "\n"), "\n") {
fmt.Fprintf(w, "%s//%s", nl, line)
nl = "\n"
}
return w... | go | func (g *Generator) makeComments(path string) (string, bool) {
loc, ok := g.file.comments[path]
if !ok {
return "", false
}
w := new(bytes.Buffer)
nl := ""
for _, line := range strings.Split(strings.TrimSuffix(loc.GetLeadingComments(), "\n"), "\n") {
fmt.Fprintf(w, "%s//%s", nl, line)
nl = "\n"
}
return w... | [
"func",
"(",
"g",
"*",
"Generator",
")",
"makeComments",
"(",
"path",
"string",
")",
"(",
"string",
",",
"bool",
")",
"{",
"loc",
",",
"ok",
":=",
"g",
".",
"file",
".",
"comments",
"[",
"path",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
... | // makeComments generates the comment string for the field, no "\n" at the end | [
"makeComments",
"generates",
"the",
"comment",
"string",
"for",
"the",
"field",
"no",
"\\",
"n",
"at",
"the",
"end"
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L1257-L1269 |
131,882 | golang/protobuf | protoc-gen-go/generator/generator.go | weak | func (g *Generator) weak(i int32) bool {
for _, j := range g.file.WeakDependency {
if j == i {
return true
}
}
return false
} | go | func (g *Generator) weak(i int32) bool {
for _, j := range g.file.WeakDependency {
if j == i {
return true
}
}
return false
} | [
"func",
"(",
"g",
"*",
"Generator",
")",
"weak",
"(",
"i",
"int32",
")",
"bool",
"{",
"for",
"_",
",",
"j",
":=",
"range",
"g",
".",
"file",
".",
"WeakDependency",
"{",
"if",
"j",
"==",
"i",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
... | // weak returns whether the ith import of the current file is a weak import. | [
"weak",
"returns",
"whether",
"the",
"ith",
"import",
"of",
"the",
"current",
"file",
"is",
"a",
"weak",
"import",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L1276-L1283 |
131,883 | golang/protobuf | protoc-gen-go/generator/generator.go | TypeName | func (g *Generator) TypeName(obj Object) string {
return g.DefaultPackageName(obj) + CamelCaseSlice(obj.TypeName())
} | go | func (g *Generator) TypeName(obj Object) string {
return g.DefaultPackageName(obj) + CamelCaseSlice(obj.TypeName())
} | [
"func",
"(",
"g",
"*",
"Generator",
")",
"TypeName",
"(",
"obj",
"Object",
")",
"string",
"{",
"return",
"g",
".",
"DefaultPackageName",
"(",
"obj",
")",
"+",
"CamelCaseSlice",
"(",
"obj",
".",
"TypeName",
"(",
")",
")",
"\n",
"}"
] | // TypeName is the printed name appropriate for an item. If the object is in the current file,
// TypeName drops the package name and underscores the rest.
// Otherwise the object is from another package; and the result is the underscored
// package name followed by the item name.
// The result always has an initial ca... | [
"TypeName",
"is",
"the",
"printed",
"name",
"appropriate",
"for",
"an",
"item",
".",
"If",
"the",
"object",
"is",
"in",
"the",
"current",
"file",
"TypeName",
"drops",
"the",
"package",
"name",
"and",
"underscores",
"the",
"rest",
".",
"Otherwise",
"the",
"... | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L1596-L1598 |
131,884 | golang/protobuf | protoc-gen-go/generator/generator.go | getter | func (f *simpleField) getter(g *Generator, mc *msgCtx) {
star := ""
tname := f.goType
if needsStar(f.protoType) && tname[0] == '*' {
tname = tname[1:]
star = "*"
}
if f.deprecated != "" {
g.P(f.deprecated)
}
g.P("func (m *", mc.goName, ") ", Annotate(mc.message.file, f.fullPath, f.getterName), "() "+tname+... | go | func (f *simpleField) getter(g *Generator, mc *msgCtx) {
star := ""
tname := f.goType
if needsStar(f.protoType) && tname[0] == '*' {
tname = tname[1:]
star = "*"
}
if f.deprecated != "" {
g.P(f.deprecated)
}
g.P("func (m *", mc.goName, ") ", Annotate(mc.message.file, f.fullPath, f.getterName), "() "+tname+... | [
"func",
"(",
"f",
"*",
"simpleField",
")",
"getter",
"(",
"g",
"*",
"Generator",
",",
"mc",
"*",
"msgCtx",
")",
"{",
"star",
":=",
"\"",
"\"",
"\n",
"tname",
":=",
"f",
".",
"goType",
"\n",
"if",
"needsStar",
"(",
"f",
".",
"protoType",
")",
"&&"... | // getter prints the getter for the field. | [
"getter",
"prints",
"the",
"getter",
"for",
"the",
"field",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L1811-L1841 |
131,885 | golang/protobuf | protoc-gen-go/generator/generator.go | getter | func (f *oneofField) getter(g *Generator, mc *msgCtx) {
// The discriminator type
g.P("type ", f.goType, " interface {")
g.P(f.goType, "()")
g.P("}")
g.P()
// The subField types, fulfilling the discriminator type contract
for _, sf := range f.subFields {
g.P("type ", Annotate(mc.message.file, sf.fullPath, sf.o... | go | func (f *oneofField) getter(g *Generator, mc *msgCtx) {
// The discriminator type
g.P("type ", f.goType, " interface {")
g.P(f.goType, "()")
g.P("}")
g.P()
// The subField types, fulfilling the discriminator type contract
for _, sf := range f.subFields {
g.P("type ", Annotate(mc.message.file, sf.fullPath, sf.o... | [
"func",
"(",
"f",
"*",
"oneofField",
")",
"getter",
"(",
"g",
"*",
"Generator",
",",
"mc",
"*",
"msgCtx",
")",
"{",
"// The discriminator type",
"g",
".",
"P",
"(",
"\"",
"\"",
",",
"f",
".",
"goType",
",",
"\"",
"\"",
")",
"\n",
"g",
".",
"P",
... | // getter for a oneof field will print additional discriminators and interfaces for the oneof,
// also it prints all the getters for the sub fields. | [
"getter",
"for",
"a",
"oneof",
"field",
"will",
"print",
"additional",
"discriminators",
"and",
"interfaces",
"for",
"the",
"oneof",
"also",
"it",
"prints",
"all",
"the",
"getters",
"for",
"the",
"sub",
"fields",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L1915-L1951 |
131,886 | golang/protobuf | protoc-gen-go/generator/generator.go | generateDefaultConstants | func (g *Generator) generateDefaultConstants(mc *msgCtx, topLevelFields []topLevelField) {
// Collect fields that can have defaults
dFields := []defField{}
for _, pf := range topLevelFields {
if f, ok := pf.(*oneofField); ok {
for _, osf := range f.subFields {
dFields = append(dFields, osf)
}
continue... | go | func (g *Generator) generateDefaultConstants(mc *msgCtx, topLevelFields []topLevelField) {
// Collect fields that can have defaults
dFields := []defField{}
for _, pf := range topLevelFields {
if f, ok := pf.(*oneofField); ok {
for _, osf := range f.subFields {
dFields = append(dFields, osf)
}
continue... | [
"func",
"(",
"g",
"*",
"Generator",
")",
"generateDefaultConstants",
"(",
"mc",
"*",
"msgCtx",
",",
"topLevelFields",
"[",
"]",
"topLevelField",
")",
"{",
"// Collect fields that can have defaults",
"dFields",
":=",
"[",
"]",
"defField",
"{",
"}",
"\n",
"for",
... | // generateDefaultConstants adds constants for default values if needed, which is only if the default value is.
// explicit in the proto. | [
"generateDefaultConstants",
"adds",
"constants",
"for",
"default",
"values",
"if",
"needed",
"which",
"is",
"only",
"if",
"the",
"default",
"value",
"is",
".",
"explicit",
"in",
"the",
"proto",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L1976-L2048 |
131,887 | golang/protobuf | protoc-gen-go/generator/generator.go | generateOneofFuncs | func (g *Generator) generateOneofFuncs(mc *msgCtx, topLevelFields []topLevelField) {
ofields := []*oneofField{}
for _, f := range topLevelFields {
if o, ok := f.(*oneofField); ok {
ofields = append(ofields, o)
}
}
if len(ofields) == 0 {
return
}
// OneofFuncs
g.P("// XXX_OneofWrappers is for the intern... | go | func (g *Generator) generateOneofFuncs(mc *msgCtx, topLevelFields []topLevelField) {
ofields := []*oneofField{}
for _, f := range topLevelFields {
if o, ok := f.(*oneofField); ok {
ofields = append(ofields, o)
}
}
if len(ofields) == 0 {
return
}
// OneofFuncs
g.P("// XXX_OneofWrappers is for the intern... | [
"func",
"(",
"g",
"*",
"Generator",
")",
"generateOneofFuncs",
"(",
"mc",
"*",
"msgCtx",
",",
"topLevelFields",
"[",
"]",
"topLevelField",
")",
"{",
"ofields",
":=",
"[",
"]",
"*",
"oneofField",
"{",
"}",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"t... | // generateOneofFuncs adds all the utility functions for oneof, including marshalling, unmarshalling and sizer. | [
"generateOneofFuncs",
"adds",
"all",
"the",
"utility",
"functions",
"for",
"oneof",
"including",
"marshalling",
"unmarshalling",
"and",
"sizer",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L2066-L2089 |
131,888 | golang/protobuf | protoc-gen-go/generator/generator.go | generateGetters | func (g *Generator) generateGetters(mc *msgCtx, topLevelFields []topLevelField) {
for _, pf := range topLevelFields {
pf.getter(g, mc)
}
} | go | func (g *Generator) generateGetters(mc *msgCtx, topLevelFields []topLevelField) {
for _, pf := range topLevelFields {
pf.getter(g, mc)
}
} | [
"func",
"(",
"g",
"*",
"Generator",
")",
"generateGetters",
"(",
"mc",
"*",
"msgCtx",
",",
"topLevelFields",
"[",
"]",
"topLevelField",
")",
"{",
"for",
"_",
",",
"pf",
":=",
"range",
"topLevelFields",
"{",
"pf",
".",
"getter",
"(",
"g",
",",
"mc",
"... | // generateGetters adds getters for all fields, including oneofs and weak fields when applicable. | [
"generateGetters",
"adds",
"getters",
"for",
"all",
"fields",
"including",
"oneofs",
"and",
"weak",
"fields",
"when",
"applicable",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L2114-L2118 |
131,889 | golang/protobuf | protoc-gen-go/generator/generator.go | generateSetters | func (g *Generator) generateSetters(mc *msgCtx, topLevelFields []topLevelField) {
for _, pf := range topLevelFields {
pf.setter(g, mc)
}
} | go | func (g *Generator) generateSetters(mc *msgCtx, topLevelFields []topLevelField) {
for _, pf := range topLevelFields {
pf.setter(g, mc)
}
} | [
"func",
"(",
"g",
"*",
"Generator",
")",
"generateSetters",
"(",
"mc",
"*",
"msgCtx",
",",
"topLevelFields",
"[",
"]",
"topLevelField",
")",
"{",
"for",
"_",
",",
"pf",
":=",
"range",
"topLevelFields",
"{",
"pf",
".",
"setter",
"(",
"g",
",",
"mc",
"... | // generateSetters add setters for all fields, including oneofs and weak fields when applicable. | [
"generateSetters",
"add",
"setters",
"for",
"all",
"fields",
"including",
"oneofs",
"and",
"weak",
"fields",
"when",
"applicable",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L2121-L2125 |
131,890 | golang/protobuf | protoc-gen-go/generator/generator.go | mapFieldKeys | func mapFieldKeys(m map[*descriptor.FieldDescriptorProto]string) []*descriptor.FieldDescriptorProto {
keys := make([]*descriptor.FieldDescriptorProto, 0, len(m))
for k := range m {
keys = append(keys, k)
}
sort.Sort(byTypeName(keys))
return keys
} | go | func mapFieldKeys(m map[*descriptor.FieldDescriptorProto]string) []*descriptor.FieldDescriptorProto {
keys := make([]*descriptor.FieldDescriptorProto, 0, len(m))
for k := range m {
keys = append(keys, k)
}
sort.Sort(byTypeName(keys))
return keys
} | [
"func",
"mapFieldKeys",
"(",
"m",
"map",
"[",
"*",
"descriptor",
".",
"FieldDescriptorProto",
"]",
"string",
")",
"[",
"]",
"*",
"descriptor",
".",
"FieldDescriptorProto",
"{",
"keys",
":=",
"make",
"(",
"[",
"]",
"*",
"descriptor",
".",
"FieldDescriptorProt... | // mapFieldKeys returns the keys of m in a consistent order. | [
"mapFieldKeys",
"returns",
"the",
"keys",
"of",
"m",
"in",
"a",
"consistent",
"order",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L2452-L2459 |
131,891 | golang/protobuf | protoc-gen-go/generator/generator.go | unescape | func unescape(s string) string {
// NB: Sadly, we can't use strconv.Unquote because protoc will escape both
// single and double quotes, but strconv.Unquote only allows one or the
// other (based on actual surrounding quotes of its input argument).
var out []byte
for len(s) > 0 {
// regular character, or too sh... | go | func unescape(s string) string {
// NB: Sadly, we can't use strconv.Unquote because protoc will escape both
// single and double quotes, but strconv.Unquote only allows one or the
// other (based on actual surrounding quotes of its input argument).
var out []byte
for len(s) > 0 {
// regular character, or too sh... | [
"func",
"unescape",
"(",
"s",
"string",
")",
"string",
"{",
"// NB: Sadly, we can't use strconv.Unquote because protoc will escape both",
"// single and double quotes, but strconv.Unquote only allows one or the",
"// other (based on actual surrounding quotes of its input argument).",
"var",
... | // unescape reverses the "C" escaping that protoc does for default values of bytes fields.
// It is best effort in that it effectively ignores malformed input. Seemingly invalid escape
// sequences are conveyed, unmodified, into the decoded result. | [
"unescape",
"reverses",
"the",
"C",
"escaping",
"that",
"protoc",
"does",
"for",
"default",
"values",
"of",
"bytes",
"fields",
".",
"It",
"is",
"best",
"effort",
"in",
"that",
"it",
"effectively",
"ignores",
"malformed",
"input",
".",
"Seemingly",
"invalid",
... | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L2468-L2520 |
131,892 | golang/protobuf | protoc-gen-go/generator/generator.go | CamelCase | func CamelCase(s string) string {
if s == "" {
return ""
}
t := make([]byte, 0, 32)
i := 0
if s[0] == '_' {
// Need a capital letter; drop the '_'.
t = append(t, 'X')
i++
}
// Invariant: if the next letter is lower case, it must be converted
// to upper case.
// That is, we process a word at a time, wh... | go | func CamelCase(s string) string {
if s == "" {
return ""
}
t := make([]byte, 0, 32)
i := 0
if s[0] == '_' {
// Need a capital letter; drop the '_'.
t = append(t, 'X')
i++
}
// Invariant: if the next letter is lower case, it must be converted
// to upper case.
// That is, we process a word at a time, wh... | [
"func",
"CamelCase",
"(",
"s",
"string",
")",
"string",
"{",
"if",
"s",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"t",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"32",
")",
"\n",
"i",
":=",
"0",
"\n",
"if",
"s",... | // CamelCase returns the CamelCased name.
// If there is an interior underscore followed by a lower case letter,
// drop the underscore and convert the letter to upper case.
// There is a remote possibility of this rewrite causing a name collision,
// but it's so remote we're prepared to pretend it's nonexistent - sinc... | [
"CamelCase",
"returns",
"the",
"CamelCased",
"name",
".",
"If",
"there",
"is",
"an",
"interior",
"underscore",
"followed",
"by",
"a",
"lower",
"case",
"letter",
"drop",
"the",
"underscore",
"and",
"convert",
"the",
"letter",
"to",
"upper",
"case",
".",
"Ther... | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L2665-L2702 |
131,893 | golang/protobuf | protoc-gen-go/generator/generator.go | isOptional | func isOptional(field *descriptor.FieldDescriptorProto) bool {
return field.Label != nil && *field.Label == descriptor.FieldDescriptorProto_LABEL_OPTIONAL
} | go | func isOptional(field *descriptor.FieldDescriptorProto) bool {
return field.Label != nil && *field.Label == descriptor.FieldDescriptorProto_LABEL_OPTIONAL
} | [
"func",
"isOptional",
"(",
"field",
"*",
"descriptor",
".",
"FieldDescriptorProto",
")",
"bool",
"{",
"return",
"field",
".",
"Label",
"!=",
"nil",
"&&",
"*",
"field",
".",
"Label",
"==",
"descriptor",
".",
"FieldDescriptorProto_LABEL_OPTIONAL",
"\n",
"}"
] | // Is this field optional? | [
"Is",
"this",
"field",
"optional?"
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L2712-L2714 |
131,894 | golang/protobuf | protoc-gen-go/generator/generator.go | isRequired | func isRequired(field *descriptor.FieldDescriptorProto) bool {
return field.Label != nil && *field.Label == descriptor.FieldDescriptorProto_LABEL_REQUIRED
} | go | func isRequired(field *descriptor.FieldDescriptorProto) bool {
return field.Label != nil && *field.Label == descriptor.FieldDescriptorProto_LABEL_REQUIRED
} | [
"func",
"isRequired",
"(",
"field",
"*",
"descriptor",
".",
"FieldDescriptorProto",
")",
"bool",
"{",
"return",
"field",
".",
"Label",
"!=",
"nil",
"&&",
"*",
"field",
".",
"Label",
"==",
"descriptor",
".",
"FieldDescriptorProto_LABEL_REQUIRED",
"\n",
"}"
] | // Is this field required? | [
"Is",
"this",
"field",
"required?"
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L2717-L2719 |
131,895 | golang/protobuf | protoc-gen-go/generator/generator.go | isRepeated | func isRepeated(field *descriptor.FieldDescriptorProto) bool {
return field.Label != nil && *field.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED
} | go | func isRepeated(field *descriptor.FieldDescriptorProto) bool {
return field.Label != nil && *field.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED
} | [
"func",
"isRepeated",
"(",
"field",
"*",
"descriptor",
".",
"FieldDescriptorProto",
")",
"bool",
"{",
"return",
"field",
".",
"Label",
"!=",
"nil",
"&&",
"*",
"field",
".",
"Label",
"==",
"descriptor",
".",
"FieldDescriptorProto_LABEL_REPEATED",
"\n",
"}"
] | // Is this field repeated? | [
"Is",
"this",
"field",
"repeated?"
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L2722-L2724 |
131,896 | golang/protobuf | protoc-gen-go/generator/generator.go | isScalar | func isScalar(field *descriptor.FieldDescriptorProto) bool {
if field.Type == nil {
return false
}
switch *field.Type {
case descriptor.FieldDescriptorProto_TYPE_DOUBLE,
descriptor.FieldDescriptorProto_TYPE_FLOAT,
descriptor.FieldDescriptorProto_TYPE_INT64,
descriptor.FieldDescriptorProto_TYPE_UINT64,
des... | go | func isScalar(field *descriptor.FieldDescriptorProto) bool {
if field.Type == nil {
return false
}
switch *field.Type {
case descriptor.FieldDescriptorProto_TYPE_DOUBLE,
descriptor.FieldDescriptorProto_TYPE_FLOAT,
descriptor.FieldDescriptorProto_TYPE_INT64,
descriptor.FieldDescriptorProto_TYPE_UINT64,
des... | [
"func",
"isScalar",
"(",
"field",
"*",
"descriptor",
".",
"FieldDescriptorProto",
")",
"bool",
"{",
"if",
"field",
".",
"Type",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"switch",
"*",
"field",
".",
"Type",
"{",
"case",
"descriptor",
".",
"... | // Is this field a scalar numeric type? | [
"Is",
"this",
"field",
"a",
"scalar",
"numeric",
"type?"
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L2727-L2750 |
131,897 | golang/protobuf | protoc-gen-go/generator/generator.go | badToUnderscore | func badToUnderscore(r rune) rune {
if unicode.IsLetter(r) || unicode.IsDigit(r) || r == '_' {
return r
}
return '_'
} | go | func badToUnderscore(r rune) rune {
if unicode.IsLetter(r) || unicode.IsDigit(r) || r == '_' {
return r
}
return '_'
} | [
"func",
"badToUnderscore",
"(",
"r",
"rune",
")",
"rune",
"{",
"if",
"unicode",
".",
"IsLetter",
"(",
"r",
")",
"||",
"unicode",
".",
"IsDigit",
"(",
"r",
")",
"||",
"r",
"==",
"'_'",
"{",
"return",
"r",
"\n",
"}",
"\n",
"return",
"'_'",
"\n",
"}... | // badToUnderscore is the mapping function used to generate Go names from package names,
// which can be dotted in the input .proto file. It replaces non-identifier characters such as
// dot or dash with underscore. | [
"badToUnderscore",
"is",
"the",
"mapping",
"function",
"used",
"to",
"generate",
"Go",
"names",
"from",
"package",
"names",
"which",
"can",
"be",
"dotted",
"in",
"the",
"input",
".",
"proto",
"file",
".",
"It",
"replaces",
"non",
"-",
"identifier",
"characte... | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L2755-L2760 |
131,898 | golang/protobuf | protoc-gen-go/generator/generator.go | baseName | func baseName(name string) string {
// First, find the last element
if i := strings.LastIndex(name, "/"); i >= 0 {
name = name[i+1:]
}
// Now drop the suffix
if i := strings.LastIndex(name, "."); i >= 0 {
name = name[0:i]
}
return name
} | go | func baseName(name string) string {
// First, find the last element
if i := strings.LastIndex(name, "/"); i >= 0 {
name = name[i+1:]
}
// Now drop the suffix
if i := strings.LastIndex(name, "."); i >= 0 {
name = name[0:i]
}
return name
} | [
"func",
"baseName",
"(",
"name",
"string",
")",
"string",
"{",
"// First, find the last element",
"if",
"i",
":=",
"strings",
".",
"LastIndex",
"(",
"name",
",",
"\"",
"\"",
")",
";",
"i",
">=",
"0",
"{",
"name",
"=",
"name",
"[",
"i",
"+",
"1",
":",... | // baseName returns the last path element of the name, with the last dotted suffix removed. | [
"baseName",
"returns",
"the",
"last",
"path",
"element",
"of",
"the",
"name",
"with",
"the",
"last",
"dotted",
"suffix",
"removed",
"."
] | e91709a02e0e8ff8b86b7aa913fdc9ae9498e825 | https://github.com/golang/protobuf/blob/e91709a02e0e8ff8b86b7aa913fdc9ae9498e825/protoc-gen-go/generator/generator.go#L2763-L2773 |
131,899 | hashicorp/nomad | api/operator.go | SchedulerGetConfiguration | func (op *Operator) SchedulerGetConfiguration(q *QueryOptions) (*SchedulerConfigurationResponse, *QueryMeta, error) {
var resp SchedulerConfigurationResponse
qm, err := op.c.query("/v1/operator/scheduler/configuration", &resp, q)
if err != nil {
return nil, nil, err
}
return &resp, qm, nil
} | go | func (op *Operator) SchedulerGetConfiguration(q *QueryOptions) (*SchedulerConfigurationResponse, *QueryMeta, error) {
var resp SchedulerConfigurationResponse
qm, err := op.c.query("/v1/operator/scheduler/configuration", &resp, q)
if err != nil {
return nil, nil, err
}
return &resp, qm, nil
} | [
"func",
"(",
"op",
"*",
"Operator",
")",
"SchedulerGetConfiguration",
"(",
"q",
"*",
"QueryOptions",
")",
"(",
"*",
"SchedulerConfigurationResponse",
",",
"*",
"QueryMeta",
",",
"error",
")",
"{",
"var",
"resp",
"SchedulerConfigurationResponse",
"\n",
"qm",
",",... | // SchedulerGetConfiguration is used to query the current Scheduler configuration. | [
"SchedulerGetConfiguration",
"is",
"used",
"to",
"query",
"the",
"current",
"Scheduler",
"configuration",
"."
] | 01c267b92b476a61fbdef49ba3c6b62a84509043 | https://github.com/hashicorp/nomad/blob/01c267b92b476a61fbdef49ba3c6b62a84509043/api/operator.go#L146-L153 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.