MCPcopy Index your code
hub / github.com/HDT3213/rdb / tryWriteIntString

Method tryWriteIntString

core/string.go:229–255  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

227}
228
229func (enc *Encoder) tryWriteIntString(s string) (bool, error) {
230 intVal, ok := isEncodableUint32(s)
231 if !ok {
232 return false, nil
233 }
234 var err error
235 if intVal >= math.MinInt8 && intVal <= math.MaxInt8 {
236 err = enc.write([]byte{encodeInt8Prefix, byte(int8(intVal))})
237 } else if intVal >= math.MinInt16 && intVal <= math.MaxInt16 {
238 buf := enc.buffer[0:3]
239 buf[0] = encodeInt16Prefix
240 binary.LittleEndian.PutUint16(buf[1:], uint16(int16(intVal)))
241 err = enc.write(buf)
242 } else if intVal >= math.MinInt32 && intVal <= math.MaxInt32 {
243 buf := enc.buffer[0:5]
244 buf[0] = encodeInt32Prefix
245 binary.LittleEndian.PutUint32(buf[1:], uint32(int32(intVal)))
246 err = enc.write(buf)
247 } else {
248 // beyond int32 range, but within int64 range
249 return false, nil
250 }
251 if err != nil {
252 return true, err
253 }
254 return true, nil
255}
256
257func (enc *Encoder) writeLZFString(s string) error {
258 out, err := lzf.Compress([]byte(s))

Callers 1

writeStringMethod · 0.95

Calls 2

writeMethod · 0.95
isEncodableUint32Function · 0.85

Tested by

no test coverage detected