MCPcopy Index your code
hub / github.com/subtrace/subtrace / jsonify

Function jsonify

tracer/parser.go:154–198  ·  view source on GitHub ↗
(mime string, buf []byte)

Source from the content-addressed store, hash-verified

152}
153
154func jsonify(mime string, buf []byte) ([]byte, bool) {
155 switch mime {
156 case "application/grpc":
157 switch strings.ToLower(os.Getenv("SUBTRACE_GRPC")) {
158 case "0", "n", "no", "f", "false":
159 default:
160 var arr []map[string]any
161 for len(buf) > 0 {
162 if len(buf) < 5 {
163 return nil, false
164 }
165
166 comp := buf[0]
167 size := binary.BigEndian.Uint32(buf[1:5])
168 if len(buf) < int(size) {
169 return nil, false
170 }
171 buf = buf[5:]
172
173 if int(size) > len(buf) {
174 return nil, false
175 }
176 slice := buf[:size]
177 buf = buf[size:]
178
179 if comp != 0 {
180 arr = append(arr, map[string]any{"_comp": base64.RawStdEncoding.EncodeToString(slice)})
181 continue
182 }
183
184 enc := make(map[string]any)
185 if err := decodeRawProto(1, enc, slice); err != nil {
186 return nil, false
187 }
188 arr = append(arr, enc)
189 }
190 b, err := json.Marshal(arr)
191 if err != nil {
192 return nil, false
193 }
194 return b, true
195 }
196 }
197 return nil, false
198}
199
200func (p *Parser) UseRequest(req *http.Request) {
201 sampler := newSampler(req.Body)

Callers 2

UseRequestMethod · 0.85
UseResponseMethod · 0.85

Calls 1

decodeRawProtoFunction · 0.85

Tested by

no test coverage detected