File: foo.go

package info (click to toggle)
golang-github-influxdata-yarpc 0.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 276 kB
  • sloc: makefile: 2
file content (32 lines) | stat: -rw-r--r-- 522 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package foo

type fooCodec struct {
}

func (fooCodec) Marshal(v interface{}) ([]byte, error) {
	switch t := v.(type) {
	case *Request:
		return []byte(t.In), nil
	case *Response:
		return []byte(t.Out), nil
	default:
		panic("invalid type")
	}
}

func (fooCodec) Unmarshal(data []byte, v interface{}) error {
	str := string(data)
	switch t := v.(type) {
	case *Request:
		t.In = str
	case *Response:
		t.Out = str
	default:
		panic("invalid type")
	}
	return nil
}

func (fooCodec) String() string {
	return "FooCodec"
}