github.com/bhojpur/cache@v0.0.4/pkg/hack/detrand.go (about) 1 package hack 2 3 // Copyright (c) 2018 Bhojpur Consulting Private Limited, India. All rights reserved. 4 5 // Permission is hereby granted, free of charge, to any person obtaining a copy 6 // of this software and associated documentation files (the "Software"), to deal 7 // in the Software without restriction, including without limitation the rights 8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 // copies of the Software, and to permit persons to whom the Software is 10 // furnished to do so, subject to the following conditions: 11 12 // The above copyright notice and this permission notice shall be included in 13 // all copies or substantial portions of the Software. 14 15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 // THE SOFTWARE. 22 23 import ( 24 _ "unsafe" 25 ) 26 27 // DisableProtoBufRandomness disables the random insertion of whitespace characters when 28 // serializing Protocol Buffers in textual form (both when serializing to JSON or to ProtoText) 29 // 30 // Since the introduction of the APIv2 for Protocol Buffers, the default serializers in the 31 // package insert random whitespace characters that don't change the meaning of the serialized 32 // code but make byte-wise comparison impossible. The rationale behind this decision is as follows: 33 // 34 // "The ProtoBuf authors believe that golden tests are Wrong" 35 // 36 // Fine. Unfortunately, Vitess makes extensive use of golden tests through its test suite, which 37 // expect byte-wise comparison to be stable between test runs. Using the new version of the 38 // package would require us to rewrite hundreds of tests, or alternatively, we could disable 39 // the randomness and call it a day. The method required to disable the randomness is not public, but 40 // that won't stop us because we're good at computers. 41 // 42 //go:linkname DisableProtoBufRandomness google.golang.org/protobuf/internal/detrand.Disable 43 func DisableProtoBufRandomness()