mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-01 03:14:16 +00:00
97a87391b1
Create a new internal/strs package that unifies common functionality: * Since protobuf itself pseudo-specifies at least 4 different camel-case and snake-case conversion functions, we define all variants in one place. * We move the internal/filedesc.nameBuilder function to this package. We simplify its implementation to not depend on a strings.Builder fork under the hood since the semantics we desire is simpler than what strings.Builder provides. * We use strs.Builder in reflect/protodesc in its construction of all the full names. This is perfect use case of strs.Builder since all full names within a file descriptor share the same lifetime. * Add an UnsafeString and UnsafeBytes cast function that will be useful in the near future for optimizing encoding/prototext and encoding/protojson. Change-Id: I2cf07cbaf6f72e5f9fd6ae3d37b0d46f6af2ad59 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/185198 Reviewed-by: Damien Neil <dneil@google.com>
28 lines
585 B
Go
28 lines
585 B
Go
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// +build purego appengine
|
|
|
|
package strs
|
|
|
|
import pref "google.golang.org/protobuf/reflect/protoreflect"
|
|
|
|
func UnsafeString(b []byte) string {
|
|
return string(b)
|
|
}
|
|
|
|
func UnsafeBytes(s string) []byte {
|
|
return []byte(s)
|
|
}
|
|
|
|
type Builder struct{}
|
|
|
|
func (*Builder) AppendFullName(prefix pref.FullName, name pref.Name) pref.FullName {
|
|
return prefix.Append(name)
|
|
}
|
|
|
|
func (*Builder) MakeString(b []byte) string {
|
|
return string(b)
|
|
}
|