public class RpcMessage
extends java.lang.Object
The Perforce RPC scheme encodes messages for the client -- warnings, fatal errors, user errors, infomercials, etc., with an integer code (usually codeX in the incoming packet, where X is 0, 1, 2, etc., i.e. there can be multiple codes in one packet) and a corresponding formatted message (keyed with fmtX, where the X corresponds to the code, etc.). The integer code encodes severity and generic levels, at least, and needs to be unpacked carefully before interpretation, especially as it comes across the wire as a string.
The apparent generic packing for codes looks like this:
((sev<<28)|(arg<<24)|(gen<<16)|(sub<<10)|cod)
where sev == severity, arg == arg count, gen == generic code,
sub == subsystem (client vs. server. etc.), and cod is the
actual individual error code.
The integer code is assumed by all sides of the wire to decode into four bytes. We attempt to make this so....
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CODE
CODE - code
|
static java.lang.String |
FMT
FMT - fmt
|
static int |
NO_GENERIC_CODE_FOUND
What getGeneric() returns if it can't find a plausible
error generic level in a candidate string.
|
Constructor and Description |
---|
RpcMessage(ClientMessage.ClientMessageId id,
int severity,
int generic,
java.lang.String[] argStrs) |
RpcMessage(int subSystem,
int code,
int severity,
int generic,
java.lang.String[] fmtStrs,
java.lang.String[] argNameStrs,
java.lang.String[] argStrs) |
Modifier and Type | Method and Description |
---|---|
java.lang.String[] |
getArgNameStrs() |
java.lang.String[] |
getArgStrs() |
int |
getCode() |
java.lang.String[] |
getFmtStrs() |
int |
getGeneric() |
static int |
getGeneric(java.lang.String codeStr)
Given a string encoding of a complete error code, return
its generic error code value ("generic" being Perforce's
rather odd name for the specific error value).
|
int |
getSeverity() |
static int |
getSeverity(java.lang.String codeStr)
Given a string encoding of a complete error code off the wire,
return its severity level, if possible.
|
int |
getSubSystem() |
static int |
getSubsystem(java.lang.String codeStr)
Given a string encoding of a complete error code, return
its subsystem error code value.
|
static java.lang.String |
interpolateArgs(java.lang.String fmtStr,
java.util.Map<java.lang.String,java.lang.Object> map)
Try to fill in the %...% bits in a typical server text message.
|
java.lang.String |
makeErrorCodeString()
Encode the various error code subcodes as a string
as seen on the wire.
|
void |
setArgNameStrs(java.lang.String[] argNameStrs) |
void |
setArgStrs(java.lang.String[] argStrs) |
void |
setCode(int code) |
void |
setFmtStrs(java.lang.String[] fmtStrs) |
void |
setGeneric(int generic) |
void |
setSeverity(int severity) |
void |
setSubSystem(int subSystem) |
java.util.Map<java.lang.String,java.lang.Object> |
toMap() |
public static final int NO_GENERIC_CODE_FOUND
public static final java.lang.String CODE
public static final java.lang.String FMT
public RpcMessage(int subSystem, int code, int severity, int generic, java.lang.String[] fmtStrs, java.lang.String[] argNameStrs, java.lang.String[] argStrs)
public RpcMessage(ClientMessage.ClientMessageId id, int severity, int generic, java.lang.String[] argStrs)
id
- idseverity
- severitygeneric
- genericargStrs
- argStrspublic static java.lang.String interpolateArgs(java.lang.String fmtStr, java.util.Map<java.lang.String,java.lang.Object> map)
fmtStr="Access for user '%user%' has not been enabled by 'p4 protect'." args[0]="nouser"Harder example, with alternates:
[%argc% - no|No] such file(s).Another difficult example, with a different type of alternate:
fmtStr=%change% created[ with %workCount% open file(s)][ fixing %jobCount% job(s)]Typically used in this implementation for error messages coming back from the server, but can have broader uses with untagged server output in general.
FIXME: this is a rather ad-hoc and not particularly efficient algorithm, which will be replaced by a better implementation when I get more experience with relative efficiencies, etc. -- (HR).
FIXME: provide a version that works with multiple format strings -- HR.
fmtStr
- fmtStrmap
- mappublic java.util.Map<java.lang.String,java.lang.Object> toMap()
public static int getSeverity(java.lang.String codeStr)
codeStr
- candidate error codepublic static int getGeneric(java.lang.String codeStr)
codeStr
- candidate error codepublic static int getSubsystem(java.lang.String codeStr)
codeStr
- candidate error codepublic java.lang.String makeErrorCodeString()
# define ErrorOf( sub, cod, sev, gen, arg ) \
((sev<<28)|(arg<<24)|(gen<<16)|(sub<<10)|cod)
public int getSeverity()
public void setSeverity(int severity)
public int getSubSystem()
public void setSubSystem(int subSystem)
public int getGeneric()
public void setGeneric(int generic)
public int getCode()
public void setCode(int code)
public java.lang.String[] getFmtStrs()
public void setFmtStrs(java.lang.String[] fmtStrs)
public java.lang.String[] getArgStrs()
public void setArgStrs(java.lang.String[] argStrs)
public java.lang.String[] getArgNameStrs()
public void setArgNameStrs(java.lang.String[] argNameStrs)