Changeset 488 in code for trunk/msgstore_memory.go


Ignore:
Timestamp:
Mar 31, 2021, 3:57:24 PM (4 years ago)
Author:
contact
Message:

Use BARE for internal message IDs

This allows to have shorter and more future-proof IDs. This also
guarantees the IDs will only use reasonable ASCII characters (no
spaces), removing the need to encode them for PING/PONG tokens.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/msgstore_memory.go

    r444 r488  
    33import (
    44        "fmt"
    5         "strconv"
    65        "time"
    76
     7        "git.sr.ht/~sircmpwn/go-bare"
    88        "gopkg.in/irc.v3"
    99)
     
    1111const messageRingBufferCap = 4096
    1212
     13type memoryMsgID struct {
     14        Seq bare.Uint
     15}
     16
     17func (memoryMsgID) msgIDType() msgIDType {
     18        return msgIDMemory
     19}
     20
    1321func parseMemoryMsgID(s string) (netID int64, entity string, seq uint64, err error) {
    14         netID, entity, extra, err := parseMsgID(s)
     22        var id memoryMsgID
     23        netID, entity, err = parseMsgID(s, &id)
    1524        if err != nil {
    1625                return 0, "", 0, err
    1726        }
    18         seq, err = strconv.ParseUint(extra, 10, 64)
    19         if err != nil {
    20                 return 0, "", 0, fmt.Errorf("failed to parse message ID %q: %v", s, err)
    21         }
    22         return netID, entity, seq, nil
     27        return netID, entity, uint64(id.Seq), nil
    2328}
    2429
    2530func formatMemoryMsgID(netID int64, entity string, seq uint64) string {
    26         extra := strconv.FormatUint(seq, 10)
    27         return formatMsgID(netID, entity, extra)
     31        id := memoryMsgID{bare.Uint(seq)}
     32        return formatMsgID(netID, entity, &id)
    2833}
    2934
Note: See TracChangeset for help on using the changeset viewer.