You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.3 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package response
import (
protocolpkg "github.com/noahlann/nnet/pkg/protocol"
responsepkg "github.com/noahlann/nnet/pkg/response"
)
// convertResponseHeaderToProtocolHeader 将响应帧头转换为协议帧头
// 默认直接返回引用避免拷贝如果需要拷贝可以使用convertResponseHeaderToProtocolHeaderWithClone
func convertResponseHeaderToProtocolHeader(responseHeader responsepkg.FrameHeader) protocolpkg.FrameHeader {
if responseHeader == nil {
return nil
}
// 默认直接返回引用(避免拷贝开销)
// response.FrameHeader和protocol.FrameHeader现在是同一个接口
if protocolHeader, ok := responseHeader.(protocolpkg.FrameHeader); ok {
return protocolHeader
}
// 如果类型不匹配理论上不应该发生返回nil
return nil
}
// convertResponseHeaderToProtocolHeaderWithClone 将响应帧头转换为协议帧头(深拷贝)
// 用于需要独立拷贝的场景
func convertResponseHeaderToProtocolHeaderWithClone(responseHeader responsepkg.FrameHeader) protocolpkg.FrameHeader {
if responseHeader == nil {
return nil
}
// 使用Clone方法进行深拷贝
if protocolHeader, ok := responseHeader.(protocolpkg.FrameHeader); ok {
return protocolHeader.Clone()
}
// 如果类型不匹配理论上不应该发生返回nil
return nil
}