func writeRequestHeaders( ctx context.Context, format tchannel.Format, appHeaders map[string]string, getWriter func() (tchannel.ArgWriter, error), ) error { headers := transport.NewHeadersWithCapacity(len(appHeaders)) // TODO: zero-alloc version for k, v := range appHeaders { headers = headers.With(k, v) } return writeHeaders(format, headers, getWriter) }
// decodeHeaders decodes headers using the format: // // nh:2 (k~2 v~2){nh} func decodeHeaders(r io.Reader) (transport.Headers, error) { reader := internal.NewReader(r) count := reader.ReadUint16() if count == 0 { return transport.Headers{}, reader.Err() } headers := transport.NewHeadersWithCapacity(int(count)) for i := 0; i < int(count) && reader.Err() == nil; i++ { k := reader.ReadLen16String() v := reader.ReadLen16String() headers = headers.With(k, v) } return headers, reader.Err() }