Skip to content

Commit

Permalink
all: minor documentation adjustments (#1112)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsnet committed May 4, 2020
1 parent 8d9af28 commit b5de78c
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 33 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ We recommend that new code use the `google.golang.org/protobuf` module.

Versions v1.4 and later of `github.com/golang/protobuf` are implemented
in terms of `google.golang.org/protobuf`.
Programs which use both modules should use at least version v1.4 of this one.
Programs which use both modules must use at least version v1.4 of this one.

See the
[developer guide for protocol buffers in Go](https://developers.google.com/protocol-buffers/docs/gotutorial)
for a general guide for how to get started using protobufs in Go.

See
[release note documentation](https://github.com/golang/protobuf/releases)
Expand Down Expand Up @@ -51,7 +55,7 @@ Summary of the packages provided by this module:
Package `wrappers` is the generated package for
`google/protobuf/wrappers.proto`.
* [`ptypes/struct`](https://pkg.go.dev/github.com/golang/protobuf/ptypes/struct):
Package `struct` is the generated package for
Package `structpb` is the generated package for
`google/protobuf/struct.proto`.
* [`protoc-gen-go/descriptor`](https://pkg.go.dev/github.com/golang/protobuf/protoc-gen-go/descriptor):
Package `descriptor` is the generated package for
Expand Down
14 changes: 7 additions & 7 deletions descriptor/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Package descriptor provides functions for obtaining the protocol buffer
// descriptors of generated Go types.
//
// Deprecated: Use the "google.golang.org/protobuf/reflect/protoreflect"
// package instead to obtain an EnumDescriptor or MessageDescriptor in order to
// Deprecated: See the "google.golang.org/protobuf/reflect/protoreflect" package
// for how to obtain an EnumDescriptor or MessageDescriptor in order to
// programatically interact with the protobuf type system.
package descriptor

Expand Down Expand Up @@ -99,8 +99,8 @@ func deriveRawDescriptor(d protoreflect.Descriptor) ([]byte, []int) {
return file, idxs
}

// EnumRawDescriptor returns the GZIP'd raw file descriptor containing the
// enum and the index path to reach the enum declaration.
// EnumRawDescriptor returns the GZIP'd raw file descriptor representing
// the enum and the index path to reach the enum declaration.
// The returned slices must not be mutated.
func EnumRawDescriptor(e proto.GeneratedEnum) ([]byte, []int) {
if ev, ok := e.(interface{ EnumDescriptor() ([]byte, []int) }); ok {
Expand All @@ -110,7 +110,7 @@ func EnumRawDescriptor(e proto.GeneratedEnum) ([]byte, []int) {
return deriveRawDescriptor(ed.Descriptor())
}

// MessageRawDescriptor returns the GZIP'd raw file descriptor containing
// MessageRawDescriptor returns the GZIP'd raw file descriptor representing
// the message and the index path to reach the message declaration.
// The returned slices must not be mutated.
func MessageRawDescriptor(m proto.GeneratedMessage) ([]byte, []int) {
Expand Down Expand Up @@ -148,7 +148,7 @@ func deriveFileDescriptor(rawDesc []byte) *descriptorpb.FileDescriptorProto {
return fd
}

// EnumDescriptorProto returns the file descriptor proto containing
// EnumDescriptorProto returns the file descriptor proto representing
// the enum and the enum descriptor proto for the enum itself.
// The returned proto messages must not be mutated.
func EnumDescriptorProto(e proto.GeneratedEnum) (*descriptorpb.FileDescriptorProto, *descriptorpb.EnumDescriptorProto) {
Expand All @@ -168,7 +168,7 @@ func EnumDescriptorProto(e proto.GeneratedEnum) (*descriptorpb.FileDescriptorPro
return fd, ed
}

// MessageDescriptorProto returns the file descriptor proto containing
// MessageDescriptorProto returns the file descriptor proto representing
// the message and the message descriptor proto for the message itself.
// The returned proto messages must not be mutated.
func MessageDescriptorProto(m proto.GeneratedMessage) (*descriptorpb.FileDescriptorProto, *descriptorpb.DescriptorProto) {
Expand Down
4 changes: 2 additions & 2 deletions jsonpb/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

const wrapJSONUnmarshalV2 = false

// UnmarshalNext unmarshals the next object in a JSON object stream into m.
// UnmarshalNext unmarshals the next JSON object from d into m.
func UnmarshalNext(d *json.Decoder, m proto.Message) error {
return new(Unmarshaler).UnmarshalNext(d, m)
}
Expand Down Expand Up @@ -68,7 +68,7 @@ func (u *Unmarshaler) Unmarshal(r io.Reader, m proto.Message) error {
return u.UnmarshalNext(json.NewDecoder(r), m)
}

// UnmarshalNext unmarshals the next object in a JSON object stream into m.
// UnmarshalNext unmarshals the next JSON object from d into m.
func (u *Unmarshaler) UnmarshalNext(d *json.Decoder, m proto.Message) error {
if m == nil {
return errors.New("invalid nil message")
Expand Down
8 changes: 4 additions & 4 deletions jsonpb/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ type Marshaler struct {
// as opposed to string values.
EnumsAsInts bool

// EmitDefaults specifies Whether to render fields with zero values.
// EmitDefaults specifies whether to render fields with zero values.
EmitDefaults bool

// Indent controls whether the output is compact or not.
// If empty, the output is compact JSON. If non-empty, every JSON object
// If empty, the output is compact JSON. Otherwise, every JSON object
// entry and JSON array value will be on its own line.
// Each line will be preceded by repeated copies of Indent, where the
// number of copies is the current indentation depth.
Expand All @@ -62,7 +62,7 @@ type JSONPBMarshaler interface {
MarshalJSONPB(*Marshaler) ([]byte, error)
}

// Marshal marshals a protocol buffer into JSON.
// Marshal serializes a protobuf message as JSON into w.
func (jm *Marshaler) Marshal(w io.Writer, m proto.Message) error {
b, err := jm.marshal(m)
if len(b) > 0 {
Expand All @@ -73,7 +73,7 @@ func (jm *Marshaler) Marshal(w io.Writer, m proto.Message) error {
return err
}

// MarshalToString converts a protocol buffer object to JSON string.
// MarshalToString serializes a protobuf message as JSON in string form.
func (jm *Marshaler) MarshalToString(m proto.Message) (string, error) {
b, err := jm.marshal(m)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions jsonpb/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package jsonpb provides marshaling and unmarshaling between a protocol buffer
// message and JSON. It follows the specification at
// Package jsonpb provides functionality to marshal and unmarshal between a
// protocol buffer message and JSON. It follows the specification at
// https://developers.google.com/protocol-buffers/docs/proto3#json.
//
// Do not rely on the default behavior of the standard encoding/json package
Expand All @@ -20,8 +20,8 @@ import (
"google.golang.org/protobuf/runtime/protoimpl"
)

// AnyResolver takes a type URL, present in an Any message, and resolves it into
// an instance of the associated message.
// AnyResolver takes a type URL, present in an Any message,
// and resolves it into an instance of the associated message.
type AnyResolver interface {
Resolve(typeURL string) (proto.Message, error)
}
Expand Down
14 changes: 7 additions & 7 deletions proto/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func SizeVarint(v uint64) int {
return protowire.SizeVarint(v)
}

// DecodeVarint parses a varint encoded integer from b, returning the
// integer value and the length of the varint.
// DecodeVarint parses a varint encoded integer from b,
// returning the integer value and the length of the varint.
// It returns (0, 0) if there is a parse error.
func DecodeVarint(b []byte) (uint64, int) {
v, n := protowire.ConsumeVarint(b)
Expand Down Expand Up @@ -112,9 +112,9 @@ func (b *Buffer) Marshal(m Message) error {
return err
}

// Unmarshal parses the wire-format message in the buffer and places the decoded results in m.
//
// Unlike proto.Unmarshal, this does not reset the message before starting to unmarshal.
// Unmarshal parses the wire-format message in the buffer and
// places the decoded results in m.
// It does not reset m before unmarshaling.
func (b *Buffer) Unmarshal(m Message) error {
err := UnmarshalMerge(b.Unread(), m)
b.idx = len(b.buf)
Expand Down Expand Up @@ -260,7 +260,7 @@ func (b *Buffer) DecodeStringBytes() (string, error) {
}

// DecodeMessage consumes a length-prefixed message from the buffer.
// It does not reset m.
// It does not reset m before unmarshaling.
func (b *Buffer) DecodeMessage(m Message) error {
v, err := b.DecodeRawBytes(false)
if err != nil {
Expand All @@ -272,7 +272,7 @@ func (b *Buffer) DecodeMessage(m Message) error {
// DecodeGroup consumes a message group from the buffer.
// It assumes that the start group marker has already been consumed and
// consumes all bytes until (and including the end group marker).
// It does not reset m.
// It does not reset m before unmarshaling.
func (b *Buffer) DecodeGroup(m Message) error {
v, n, err := consumeGroup(b.buf[b.idx:])
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions proto/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func HasExtension(m Message, xt *ExtensionDesc) (has bool) {
return has
}

// ClearExtension removes the the exntesion field from m
// ClearExtension removes the extension field from m
// either as an explicitly populated field or as an unknown field.
func ClearExtension(m Message, xt *ExtensionDesc) {
mr := MessageReflect(m)
Expand Down Expand Up @@ -108,7 +108,7 @@ func ClearAllExtensions(m Message) {
clearUnknown(mr, mr.Descriptor().ExtensionRanges())
}

// GetExtension retrieves a proto2 extended field from pb.
// GetExtension retrieves a proto2 extended field from m.
//
// If the descriptor is type complete (i.e., ExtensionDesc.ExtensionType is non-nil),
// then GetExtension parses the encoded field and returns a Go value of the specified type.
Expand Down
8 changes: 4 additions & 4 deletions proto/text_encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,16 @@ var (
)

// MarshalText writes the proto text format of m to w.
func MarshalText(w io.Writer, pb Message) error { return defaultTextMarshaler.Marshal(w, pb) }
func MarshalText(w io.Writer, m Message) error { return defaultTextMarshaler.Marshal(w, m) }

// MarshalTextString returns a proto text formatted string of m.
func MarshalTextString(pb Message) string { return defaultTextMarshaler.Text(pb) }
func MarshalTextString(m Message) string { return defaultTextMarshaler.Text(m) }

// CompactText writes the compact proto text format of m to w.
func CompactText(w io.Writer, pb Message) error { return compactTextMarshaler.Marshal(w, pb) }
func CompactText(w io.Writer, m Message) error { return compactTextMarshaler.Marshal(w, m) }

// CompactTextString returns a compact proto text formatted string of m.
func CompactTextString(pb Message) string { return compactTextMarshaler.Text(pb) }
func CompactTextString(m Message) string { return compactTextMarshaler.Text(m) }

var (
newline = []byte("\n")
Expand Down
3 changes: 2 additions & 1 deletion protoc-gen-go/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
// This package is excluded from the Go protocol buffer compatibility guarantee
// and may be deleted at some point in the future.
//
// Deprecated: Do not use.
// Deprecated: Use the "google.golang.org/protobuf/compiler/protogen" package
// instead to write protoc plugins in Go.
package generator

import (
Expand Down

0 comments on commit b5de78c

Please sign in to comment.