MCPcopy
hub / github.com/NVIDIA/aistore / Example_headers

Function Example_headers

transport/obj_test.go:108–146  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

106}
107
108func Example_headers() {
109 f := func(w http.ResponseWriter, r *http.Request) {
110 body, err := io.ReadAll(r.Body)
111 if err != nil {
112 panic(err)
113 }
114 if len(body) == 0 {
115 return
116 }
117 var (
118 hdr transport.ObjHdr
119 hlen, off int
120 )
121 for {
122 hlen = int(binary.BigEndian.Uint64(body[off:]))
123 off += 16 // hlen and hlen-checksum
124 hdr = transport.ExtObjHeader(body[off:], hlen)
125 if !transport.ReservedOpcode(hdr.Opcode) {
126 fmt.Printf("%+v (%d)\n", hdr, hlen)
127 off += hlen + int(hdr.ObjAttrs.Size)
128 } else {
129 break
130 }
131 }
132 }
133
134 ts := httptest.NewServer(http.HandlerFunc(f))
135 defer ts.Close()
136
137 httpclient := transport.NewIntraDataClient()
138 stream := transport.NewObjStream(httpclient, ts.URL, cos.GenTie(), nil)
139
140 sendText(stream, lorem, duis)
141 stream.Fin()
142
143 // Output:
144 // {Bck:aws://@uuid#namespace/abc ObjName:X ObjAttrs:{Atime:663346294 Size:231 Ver:1 Cksum:xxhash[h1] CustomMD:map[]} Opaque:[] SID: Opcode:0} (69)
145 // {Bck:ais://abracadabra ObjName:p/q/s ObjAttrs:{Atime:663346294 Size:213 Ver:222222222222222222222222 Cksum:xxhash[h2] CustomMD:map[xx:11 yy:22]} Opaque:[49 50 51] SID: Opcode:0} (110)
146}
147
148func sendText(stream *transport.Stream, txt1, txt2 string) {
149 var wg sync.WaitGroup

Callers

nothing calls this directly

Calls 9

ExtObjHeaderFunction · 0.92
ReservedOpcodeFunction · 0.92
NewIntraDataClientFunction · 0.92
NewObjStreamFunction · 0.92
GenTieFunction · 0.92
sendTextFunction · 0.85
ReadAllMethod · 0.80
CloseMethod · 0.65
FinMethod · 0.45

Tested by

no test coverage detected