Skip to content

Commit

Permalink
encoding/protowire: make package publicly available
Browse files Browse the repository at this point in the history
Change-Id: I95e293c208e787a91d50e29817620535dfeaa7f2
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/219838
Reviewed-by: Damien Neil <[email protected]>
  • Loading branch information
dsnet committed Mar 20, 2020
1 parent b738ac9 commit cd108d0
Show file tree
Hide file tree
Showing 41 changed files with 1,839 additions and 1,837 deletions.
12 changes: 6 additions & 6 deletions cmd/protoc-gen-go/internal_gengo/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"unicode/utf8"

"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/internal/encoding/wire"
"google.golang.org/protobuf/encoding/protowire"

"google.golang.org/protobuf/types/descriptorpb"
)
Expand Down Expand Up @@ -146,13 +146,13 @@ func isTrackedMessage(m *messageInfo) (tracked bool) {
// annotation proto from protoc-gen-go.
b := m.Desc.Options().(*descriptorpb.MessageOptions).ProtoReflect().GetUnknown()
for len(b) > 0 {
num, typ, n := wire.ConsumeTag(b)
num, typ, n := protowire.ConsumeTag(b)
b = b[n:]
if num == trackFieldUse_fieldNumber && typ == wire.VarintType {
v, _ := wire.ConsumeVarint(b)
tracked = wire.DecodeBool(v)
if num == trackFieldUse_fieldNumber && typ == protowire.VarintType {
v, _ := protowire.ConsumeVarint(b)
tracked = protowire.DecodeBool(v)
}
m := wire.ConsumeFieldValue(num, typ, b)
m := protowire.ConsumeFieldValue(num, typ, b)
b = b[m:]
}
return tracked
Expand Down
24 changes: 12 additions & 12 deletions encoding/prototext/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"strconv"
"unicode/utf8"

"google.golang.org/protobuf/encoding/protowire"
"google.golang.org/protobuf/internal/encoding/messageset"
"google.golang.org/protobuf/internal/encoding/text"
"google.golang.org/protobuf/internal/encoding/wire"
"google.golang.org/protobuf/internal/errors"
"google.golang.org/protobuf/internal/fieldnum"
"google.golang.org/protobuf/internal/flags"
Expand Down Expand Up @@ -336,31 +336,31 @@ func (e encoder) marshalUnknown(b []byte) {
const dec = 10
const hex = 16
for len(b) > 0 {
num, wtype, n := wire.ConsumeTag(b)
num, wtype, n := protowire.ConsumeTag(b)
b = b[n:]
e.WriteName(strconv.FormatInt(int64(num), dec))

switch wtype {
case wire.VarintType:
case protowire.VarintType:
var v uint64
v, n = wire.ConsumeVarint(b)
v, n = protowire.ConsumeVarint(b)
e.WriteUint(v)
case wire.Fixed32Type:
case protowire.Fixed32Type:
var v uint32
v, n = wire.ConsumeFixed32(b)
v, n = protowire.ConsumeFixed32(b)
e.WriteLiteral("0x" + strconv.FormatUint(uint64(v), hex))
case wire.Fixed64Type:
case protowire.Fixed64Type:
var v uint64
v, n = wire.ConsumeFixed64(b)
v, n = protowire.ConsumeFixed64(b)
e.WriteLiteral("0x" + strconv.FormatUint(v, hex))
case wire.BytesType:
case protowire.BytesType:
var v []byte
v, n = wire.ConsumeBytes(b)
v, n = protowire.ConsumeBytes(b)
e.WriteString(string(v))
case wire.StartGroupType:
case protowire.StartGroupType:
e.StartMessage()
var v []byte
v, n = wire.ConsumeGroup(num, b)
v, n = protowire.ConsumeGroup(num, b)
e.marshalUnknown(v)
e.EndMessage()
default:
Expand Down
8 changes: 5 additions & 3 deletions internal/encoding/wire/wire.go → encoding/protowire/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package wire parses and formats the protobuf wire encoding.
//
// Package protowire parses and formats the raw wire encoding.
// See https://developers.google.com/protocol-buffers/docs/encoding.
package wire
//
// For marshaling and unmarshaling entire protobuf messages,
// use the "google.golang.org/protobuf/proto" package instead.
package protowire

import (
"io"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package wire
package protowire

import (
"bytes"
Expand Down
Loading

0 comments on commit cd108d0

Please sign in to comment.