Source file src/encoding/json/internal/internal.go

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build goexperiment.jsonv2
     6  
     7  package internal
     8  
     9  import "errors"
    10  
    11  // NotForPublicUse is a marker type that an API is for internal use only.
    12  // It does not perfectly prevent usage of that API, but helps to restrict usage.
    13  // Anything with this marker is not covered by the Go compatibility agreement.
    14  // Not zero-sized type, since it is used as pointer-identity.
    15  type NotForPublicUse struct{ _ [1]byte }
    16  
    17  // AllowInternalUse is passed from "json" to "jsontext" to authenticate
    18  // that the caller can have access to internal functionality.
    19  var AllowInternalUse NotForPublicUse
    20  
    21  // Sentinel error values internally shared between jsonv1 and jsonv2.
    22  var (
    23  	ErrCycle           = errors.New("encountered a cycle")
    24  	ErrNonNilReference = errors.New("value must be passed as a non-nil pointer reference")
    25  	ErrNilInterface    = errors.New("cannot derive concrete type for nil interface with finite type set")
    26  )
    27  
    28  var (
    29  	// TransformMarshalError converts a v2 error into a v1 error.
    30  	// It is called only at the top-level of a Marshal function.
    31  	TransformMarshalError func(any, error) error
    32  	// NewMarshalerError constructs a jsonv1.MarshalerError.
    33  	// It is called after a user-defined Marshal method/function fails.
    34  	NewMarshalerError func(any, error, string) error
    35  	// TransformUnmarshalError converts a v2 error into a v1 error.
    36  	// It is called only at the top-level of an Unmarshal function.
    37  	TransformUnmarshalError func(any, error) error
    38  
    39  	// NewRawNumber returns new(jsonv1.Number).
    40  	NewRawNumber func() any
    41  	// RawNumberOf returns jsonv1.Number(b).
    42  	RawNumberOf func(b []byte) any
    43  )
    44  

View as plain text