Back to

Package defval

Latest Go to latest

The latest major version is .

Published: Jun 22, 2020 | License: BSD-3-Clause | Module:


Package defval marshals and unmarshals textual forms of default values.

This package handles both the form historically used in Go struct field tags and also the form used by google.protobuf.FieldDescriptorProto.default_value since they differ in superficial ways.


func Marshal

func Marshal(v pref.Value, ev pref.EnumValueDescriptor, k pref.Kind, f Format) (string, error)

Marshal serializes v as the default string according to the given kind k. When specifying the Descriptor format for an enum kind, the associated enum value descriptor must be provided.

func Unmarshal

func Unmarshal(s string, k pref.Kind, evs pref.EnumValueDescriptors, f Format) (pref.Value, pref.EnumValueDescriptor, error)

Unmarshal deserializes the default string s according to the given kind k. When k is an enum, a list of enum value descriptors must be provided.

type Format

type Format int

Format is the serialization format used to represent the default value.

const (

	// Descriptor uses the serialization format that protoc uses with the
	// google.protobuf.FieldDescriptorProto.default_value field.
	Descriptor Format

	// GoTag uses the historical serialization format in Go struct field tags.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier