MCPcopy Create free account
hub / github.com/blues/note / wireReadHeaderTrace

Function wireReadHeaderTrace

lib/wire.go:1074–1195  ·  view source on GitHub ↗

wireReadHeaderTrace extracts protocol buffer and binary lengths with optional verbose debugging output

(version byte, header []byte, trace bool)

Source from the content-addressed store, hash-verified

1072
1073// wireReadHeaderTrace extracts protocol buffer and binary lengths with optional verbose debugging output
1074func wireReadHeaderTrace(version byte, header []byte, trace bool) (protobufLength int64, binaryLength int64, err error) {
1075 if trace {
1076 fmt.Printf(" wireReadHeader: version=%d, header len=%d\n", version, len(header))
1077 if len(header) > 0 {
1078 fmt.Printf(" Header bytes: % x\n", header)
1079 }
1080 }
1081
1082 var isValidVersion bool
1083
1084 switch version {
1085
1086 // 1 byte version == 0
1087 // 0 byte protobuf length
1088 // 0 byte binary length
1089 // 0 bytes protobuf
1090 // 0 bytes binary
1091 case 0:
1092 protobufLength = 0
1093 binaryLength = 0
1094 isValidVersion = true
1095 if trace {
1096 fmt.Printf(" Version 0: no data\n")
1097 }
1098
1099 // 1 byte version == 1
1100 // 1 byte protobuf length
1101 // 1 byte binary length
1102 // N bytes protobuf
1103 // N bytes binary
1104 case 1:
1105 protobufLength = int64(header[0])
1106 binaryLength = int64(header[1])
1107 isValidVersion = true
1108 if trace {
1109 fmt.Printf(" Version 1: protobuf=%d, binary=%d\n", protobufLength, binaryLength)
1110 }
1111
1112 // 1 byte version == 2
1113 // 1 byte protobuf length
1114 // 2 byte binary length
1115 // N bytes protobuf
1116 // N bytes binary
1117 case 2:
1118 protobufLength = int64(header[0])
1119 binaryLength = (int64(header[2]) << 8) | int64(header[1])
1120 isValidVersion = true
1121 if trace {
1122 fmt.Printf(" Version 2: protobuf=%d, binary=%d (16-bit)\n", protobufLength, binaryLength)
1123 }
1124
1125 // 1 byte version == 3
1126 // 2 byte protobuf length
1127 // 2 byte binary length
1128 // N bytes protobuf
1129 // N bytes binary
1130 case 3:
1131 protobufLength = (int64(header[1]) << 8) | int64(header[0])

Callers 2

wireReadHeaderFunction · 0.85
msgFromWireTraceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected