trpc.group/trpc-go/trpc-go@v1.0.3/transport/internal/frame/frame.go (about) 1 // 2 // 3 // Tencent is pleased to support the open source community by making tRPC available. 4 // 5 // Copyright (C) 2023 THL A29 Limited, a Tencent company. 6 // All rights reserved. 7 // 8 // If you have downloaded a copy of the tRPC source code from Tencent, 9 // please note that tRPC source code is licensed under the Apache 2.0 License, 10 // A copy of the Apache 2.0 License is included in this file. 11 // 12 // 13 14 // Package frame contains transport-level frame utilities. 15 package frame 16 17 // ShouldCopy judges whether to enable frame copy according to the current framer and options. 18 func ShouldCopy(isCopyOption, serverAsync, isSafeFramer bool) bool { 19 // The following two scenarios do not need to copy frame. 20 // Scenario 1: Framer is already safe on concurrent read. 21 if isSafeFramer { 22 return false 23 } 24 // Scenario 2: The server is in sync mod, and the caller does not want to copy frame(not stream RPC). 25 if !serverAsync && !isCopyOption { 26 return false 27 } 28 29 // Otherwise: 30 // To avoid data overwriting of the concurrent reading Framer, enable copy frame by default. 31 return true 32 }