textpb

package
v0.0.0-...-527d38f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package textpb can reformat text protos to be prettier.

It is needed because "google.golang.org/protobuf/encoding/prototext" intentionally produces unstable output (inserting spaces in random places) and it very zealously escapes JSON-valued fields making them unreadable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(blob []byte, desc protoreflect.MessageDescriptor) ([]byte, error)

Format reformats a text proto of the given type to be prettier.

Normalizes whitespaces and converts JSON-valued fields to be multi-line string literals instead of one giant string with "\n" inside. A string field can be annotated as containing JSON via field options:

import "go.chromium.org/luci/common/proto/options.proto";

message MyMessage {
  string my_field = 1 [(luci.text_pb_format) = JSON];
}

func Marshal

func Marshal(m proto.Message) ([]byte, error)

Marshal marshals the message into a pretty textproto.

Uses the global protoregistry.GlobalTypes resolved. If you need to use a custom one, use "google.golang.org/protobuf/encoding/prototext" to marshal the message into a non-pretty form and the pass the result through Format.

Types

This section is empty.

Directories

Path Synopsis
Package internal contains protos used internally in tests.
Package internal contains protos used internally in tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL