github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/p/demo/gnorkle/message/parse.gno (about) 1 package message 2 3 import "strings" 4 5 // ParseFunc parses a raw message and returns the message function 6 // type extracted from the remainder of the message. 7 func ParseFunc(rawMsg string) (FuncType, string) { 8 funcType, remainder := parseFirstToken(rawMsg) 9 return FuncType(funcType), remainder 10 } 11 12 // ParseID parses a raw message and returns the ID extracted from 13 // the remainder of the message. 14 func ParseID(rawMsg string) (string, string) { 15 return parseFirstToken(rawMsg) 16 } 17 18 func parseFirstToken(rawMsg string) (string, string) { 19 msgParts := strings.SplitN(rawMsg, ",", 2) 20 if len(msgParts) < 2 { 21 return msgParts[0], "" 22 } 23 24 return msgParts[0], msgParts[1] 25 }