protobuf-go/runtime/protolazy/protolazy.go
Michael Stapelberg eb7b468655 all: Release the Opaque API
For golang/protobuf#1657

Change-Id: I7b2b0c30506706015ce278e6054439c9ad9ef727
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/634815
TryBot-Bypass: Michael Stapelberg <stapelberg@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2024-12-11 03:16:51 -08:00

32 lines
1.1 KiB
Go

// Copyright 2024 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.
// Package protolazy controls the lazy implementation in the protobuf runtime.
//
// The following logic determines whether lazy decoding is enabled:
// 1. Lazy decoding is enabled by default, unless the environment variable
// GOPROTODEBUG=nolazy is set.
// 2. If still on, calling protolazy.Disable() turns off lazy decoding.
// 3. If still on, proto.UnmarshalOptions's NoLazyDecoding turns off
// lazy decoding for this Unmarshal operation only.
package protolazy
import (
"google.golang.org/protobuf/internal/impl"
)
// Disable disables lazy unmarshaling of opaque messages.
//
// Messages which are still on the OPEN or HYBRID API level (see
// http://go/go-opaque-proto) are never lazily unmarshalled.
//
// Fields must be annotated with [lazy = true] in their .proto file to become
// eligible for lazy unmarshaling.
func Disable() (reenable func()) {
impl.EnableLazyUnmarshal(false)
return func() {
impl.EnableLazyUnmarshal(true)
}
}