github.com/vedadiyan/sqlparser@v1.0.0/pkg/hack/detrand.go (about) 1 /* 2 Copyright 2021 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package hack 18 19 import ( 20 _ "unsafe" 21 ) 22 23 // DisableProtoBufRandomness disables the random insertion of whitespace characters when 24 // serializing Protocol Buffers in textual form (both when serializing to JSON or to ProtoText) 25 // 26 // Since the introduction of the APIv2 for Protocol Buffers, the default serializers in the 27 // package insert random whitespace characters that don't change the meaning of the serialized 28 // code but make byte-wise comparison impossible. The rationale behind this decision is as follows: 29 // 30 // "The ProtoBuf authors believe that golden tests are Wrong" 31 // 32 // Fine. Unfortunately, Vitess makes extensive use of golden tests through its test suite, which 33 // expect byte-wise comparison to be stable between test runs. Using the new version of the 34 // package would require us to rewrite hundreds of tests, or alternatively, we could disable 35 // the randomness and call it a day. The method required to disable the randomness is not public, but 36 // that won't stop us because we're good at computers. 37 // 38 // Tracking issue: https://github.com/golang/protobuf/issues/1121 39 // 40 //go:linkname DisableProtoBufRandomness google.golang.org/protobuf/internal/detrand.Disable 41 func DisableProtoBufRandomness()