Changeset 440 in code for trunk/msgstore.go


Ignore:
Timestamp:
Jan 4, 2021, 3:26:30 PM (4 years ago)
Author:
contact
Message:

Add store-agnostic message ID format

Allow to query the network ID and entity from the message ID regardless
of the underlying store used.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/msgstore.go

    r439 r440  
    22
    33import (
     4        "fmt"
     5        "strconv"
     6        "strings"
    47        "time"
    58
     
    1922        Append(network *network, entity string, msg *irc.Message) (id string, err error)
    2023}
     24
     25func formatMsgID(netID int64, entity, extra string) string {
     26        return fmt.Sprintf("%v %v %v", netID, entity, extra)
     27}
     28
     29func parseMsgID(s string) (netID int64, entity, extra string, err error) {
     30        l := strings.SplitN(s, " ", 3)
     31        if len(l) != 3 {
     32                return 0, "", "", fmt.Errorf("invalid message ID %q: expected 3 fields", s)
     33        }
     34        netID, err = strconv.ParseInt(l[0], 10, 64)
     35        if err != nil {
     36                return 0, "", "", fmt.Errorf("invalid message ID %q: %v", s, err)
     37        }
     38        return netID, l[1], l[2], nil
     39}
Note: See TracChangeset for help on using the changeset viewer.