-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommandcreationutils.go
More file actions
39 lines (34 loc) · 890 Bytes
/
commandcreationutils.go
File metadata and controls
39 lines (34 loc) · 890 Bytes
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
33
34
35
36
37
38
39
package main
import (
"fmt"
"strconv"
"time"
)
func parseExpiry(seconds int) time.Time {
currentTime := time.Now()
duration := time.Duration(seconds) * time.Second
return currentTime.Add(duration)
}
func parseByteCount(byteCountString string) int {
byteCount, _ := strconv.ParseInt(byteCountString, 10, 32)
return int(byteCount)
}
func cacheValueParser(command Command) CacheValue {
baseCmd := command.GetBaseCommand()
value := CacheValue{
Key: baseCmd.key,
Flags: baseCmd.flags,
ExpiryTime: parseExpiry(baseCmd.expiryTime),
AmountOfBytes: baseCmd.byteCount,
CreatedAt: time.Now(),
}
return value
}
func parseDataBlock(cmd Command) ([]byte, error) {
buf := make([]byte, cmd.GetBaseCommand().byteCount)
_, err := cmd.GetBaseCommand().connection.Read(buf)
if err != nil {
return nil, fmt.Errorf("error: %w", err)
}
return buf, nil
}