MCPcopy
hub / github.com/go-git/go-git / Encode

Method Encode

plumbing/protocol/packp/gitproto.go:46–73  ·  view source on GitHub ↗

Encode encodes the request into the writer.

(w io.Writer)

Source from the content-addressed store, hash-verified

44
45// Encode encodes the request into the writer.
46func (g *GitProtoRequest) Encode(w io.Writer) error {
47 if w == nil {
48 return ErrNilWriter
49 }
50
51 if err := g.validate(); err != nil {
52 return err
53 }
54
55 p := pktline.NewEncoder(w)
56 req := fmt.Sprintf("%s %s\x00", g.RequestCommand, g.Pathname)
57 if host := g.Host; host != "" {
58 req += fmt.Sprintf("host=%s\x00", host)
59 }
60
61 if len(g.ExtraParams) > 0 {
62 req += "\x00"
63 for _, param := range g.ExtraParams {
64 req += param + "\x00"
65 }
66 }
67
68 if err := p.Encode([]byte(req)); err != nil {
69 return err
70 }
71
72 return nil
73}
74
75// Decode decodes the request from the reader.
76func (g *GitProtoRequest) Decode(r io.Reader) error {

Callers 4

StartMethod · 0.95

Calls 3

validateMethod · 0.95
EncodeMethod · 0.95
NewEncoderFunction · 0.92

Tested by 3