jsonflags

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

jsonflags implements all the optional boolean flags. These flags are shared across both "json", "jsontext", and "jsonopts".

Index

Constants

View Source
const (
	// AllFlags is the set of all flags.
	AllFlags = AllCoderFlags | AllArshalV2Flags | AllArshalV1Flags

	// AllCoderFlags is the set of all encoder/decoder flags.
	AllCoderFlags = (maxCoderFlag - 1) - initFlag

	// AllArshalV2Flags is the set of all v2 marshal/unmarshal flags.
	AllArshalV2Flags = (maxArshalV2Flag - 1) - (maxCoderFlag - 1)

	// AllArshalV1Flags is the set of all v1 marshal/unmarshal flags.
	AllArshalV1Flags = (maxArshalV1Flag - 1) - (maxArshalV2Flag - 1)

	// NonBooleanFlags is the set of non-boolean flags,
	// where the value is some other concrete Go type.
	// The value of the flag is stored within jsonopts.Struct.
	NonBooleanFlags = 0 |
		Indent |
		IndentPrefix |
		ByteLimit |
		DepthLimit |
		Marshalers |
		Unmarshalers

	// DefaultV1Flags is the set of booleans flags that default to true under
	// v1 semantics. None of the non-boolean flags differ between v1 and v2.
	DefaultV1Flags = 0 |
		AllowDuplicateNames |
		AllowInvalidUTF8 |
		EscapeForHTML |
		EscapeForJS |
		Deterministic |
		FormatNilMapAsNull |
		FormatNilSliceAsNull |
		MatchCaseInsensitiveNames |
		FormatByteArrayAsArray |
		FormatTimeDurationAsNanosecond |
		IgnoreStructErrors |
		MatchCaseSensitiveDelimiter |
		MergeWithLegacySemantics |
		OmitEmptyWithLegacyDefinition |
		RejectFloatOverflow |
		ReportLegacyErrorValues |
		SkipUnaddressableMethods |
		StringifyWithLegacySemantics |
		UnmarshalArrayFromAnyLength

	// AnyWhitespace reports whether the encoded output might have any whitespace.
	AnyWhitespace = Multiline | SpaceAfterColon | SpaceAfterComma
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bools

type Bools uint64

Bools represents zero or more boolean flags, all set to true or false. The least-significant bit is the boolean value of all flags in the set. The remaining bits identify which particular flags.

In common usage, this is OR'd with 0 or 1. For example:

  • (AllowInvalidUTF8 | 0) means "AllowInvalidUTF8 is false"
  • (Multiline | Indent | 1) means "Multiline and Indent are true"
const (
	AllowDuplicateNames Bools // encode or decode
	AllowInvalidUTF8          // encode or decode
	WithinArshalCall          // encode or decode; for internal use by json.Marshal and json.Unmarshal
	OmitTopLevelNewline       // encode only; for internal use by json.Marshal and json.MarshalWrite
	PreserveRawStrings        // encode only; for internal use by jsontext.Value.Canonicalize
	CanonicalizeNumbers       // encode only; for internal use by jsontext.Value.Canonicalize
	EscapeForHTML             // encode only
	EscapeForJS               // encode only
	Multiline                 // encode only
	SpaceAfterColon           // encode only
	SpaceAfterComma           // encode only
	Indent                    // encode only; non-boolean flag
	IndentPrefix              // encode only; non-boolean flag
	ByteLimit                 // encode or decode; non-boolean flag
	DepthLimit                // encode or decode; non-boolean flag

)

Encoder and decoder flags.

const (
	StringifyNumbers          Bools // marshal or unmarshal
	Deterministic                   // marshal only
	FormatNilMapAsNull              // marshal only
	FormatNilSliceAsNull            // marshal only
	MatchCaseInsensitiveNames       // marshal or unmarshal
	DiscardUnknownMembers           // marshal only
	RejectUnknownMembers            // unmarshal only
	Marshalers                      // marshal only; non-boolean flag
	Unmarshalers                    // unmarshal only; non-boolean flag

)

Marshal and Unmarshal flags (for v2).

const (
	FormatByteArrayAsArray         Bools // marshal or unmarshal
	FormatTimeDurationAsNanosecond       // marshal or unmarshal
	IgnoreStructErrors                   // marshal or unmarshal
	MatchCaseSensitiveDelimiter          // marshal or unmarshal
	MergeWithLegacySemantics             // unmarshal
	OmitEmptyWithLegacyDefinition        // marshal
	RejectFloatOverflow                  // unmarshal
	ReportLegacyErrorValues              // marshal or unmarshal
	SkipUnaddressableMethods             // marshal or unmarshal
	StringifyWithLegacySemantics         // marshal or unmarshal
	UnmarshalAnyWithRawNumber            // unmarshal; for internal use by jsonv1.Decoder.UseNumber
	UnmarshalArrayFromAnyLength          // unmarshal

)

Marshal and Unmarshal flags (for v1).

func (Bools) JSONOptions

func (Bools) JSONOptions(internal.NotForPublicUse)

type Flags

type Flags struct{ Presence, Values uint64 }

Flags is a set of boolean flags. If the presence bit is zero, then the value bit must also be zero. The least-significant bit of both fields is always zero.

Unlike Bools, which can represent a set of bools that are all true or false, Flags represents a set of bools, each individually may be true or false.

func (*Flags) Clear

func (fs *Flags) Clear(f Bools)

Clear clears both the presence and value for the provided bool or bools. The value bit of f (i.e., the LSB) is ignored.

func (Flags) Get

func (fs Flags) Get(f Bools) bool

Get reports whether the bool (or any of the bools) is true. This is generally only used with a singular bool. The value bit of f (i.e., the LSB) is ignored.

func (Flags) Has

func (fs Flags) Has(f Bools) bool

Has reports whether the bool (or any of the bools) is set. The value bit of f (i.e., the LSB) is ignored.

func (*Flags) Join

func (dst *Flags) Join(src Flags)

Join joins two sets of flags such that the latter takes precedence.

func (*Flags) Set

func (fs *Flags) Set(f Bools)

Set sets both the presence and value for the provided bool (or set of bools).

Jump to

Keyboard shortcuts

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