MCPcopy Create free account
hub / github.com/baidu/EasyFaaS / Write

Method Write

pkg/userlog/json/jsonlogfile.go:55–84  ·  view source on GitHub ↗
(l *userlog.UserLog, buf []byte)

Source from the content-addressed store, hash-verified

53}
54
55func (f *JSONLogFile) Write(l *userlog.UserLog, buf []byte) (int, error) {
56 w := f.writer
57 if w == nil {
58 return 0, errLogClosed
59 }
60 if f.capacity <= 0 {
61 return 0, errOverCapacity
62 }
63 tmp := bytes.NewBuffer(nil)
64 i, j := 0, 0
65 for i < len(buf) {
66 j = bytes.Index(buf[i:], LineByte)
67 if j < 0 {
68 j = len(buf)
69 } else if j > 0 {
70 j = i + j
71 } else {
72 i++
73 continue
74 }
75 l.Message = buf[i:j]
76 if err := l.MarshalJSONBuf(tmp); err != nil {
77 return 0, err
78 }
79 i = j + 1
80 }
81 w.Write(tmp.Bytes())
82 atomic.AddInt32(&f.capacity, int32(-i))
83 return i, nil
84}
85
86func (f *JSONLogFile) Close() error {
87 w := f.writer

Callers 1

TestJSONLogFileFunction · 0.95

Calls 3

MarshalJSONBufMethod · 0.80
BytesMethod · 0.80
WriteMethod · 0.65

Tested by 1

TestJSONLogFileFunction · 0.76