public static byte ToTagByte(OscArgType argType) { switch (argType) { case OscArgType.Null: return(OscConst.tagNullByte); case OscArgType.Impulse: return(OscConst.tagImpulseByte); case OscArgType.Bool: return(OscConst.tagFalseByte); // Bool defaults to false case OscArgType.Float: return(OscConst.tagFloatByte); case OscArgType.Int: return(OscConst.tagIntByte); case OscArgType.Char: return(OscConst.tagCharByte); case OscArgType.Color: return(OscConst.tagColorByte); case OscArgType.Midi: return(OscConst.tagMidiByte); case OscArgType.Double: return(OscConst.tagDoubleByte); case OscArgType.Long: return(OscConst.tagLongByte); case OscArgType.TimeTag: return(OscConst.tagTimetagByte); case OscArgType.String: return(OscConst.tagStringByte); case OscArgType.Blob: return(OscConst.tagBlobByte); } return(OscConst.tagUnsupportedByte); }
public OscArgInfo(byte tagByte, OscArgType argType, short byteCount, short byteIndex = 0) { this.tagByte = tagByte; this.argType = argType; this.byteCount = byteCount; this.byteIndex = byteIndex; }
StringBuilder StartBuildingInvalidTryGetString(StringBuilder sb, OscArgType requestedType) { sb.Append("TryGet failed to read "); sb.Append(requestedType); sb.Append(" from message with address \""); sb.Append(_address); sb.Append("\".\n"); return(sb); }
/// <summary> /// Returns the argument type at index. /// </summary> public bool TryGetArgType(int index, out OscArgType type) { if (index < 0 || index >= _argInfo.Count) { type = OscArgType.Unsupported; return(false); } type = OscConverter.ToArgType(_argInfo[index].tagByte); return(true); }
bool ValidateTryGet(int index, OscArgType requestedType) { // Arg bounds. if (index < 0 || index >= _argInfo.Count) { StringBuilder sb = StartBuildingInvalidTryGetString(OscDebug.BuildText(this)); sb.Append("Requested argument index "); sb.Append(index); sb.Append(" is out of bounds. Message has "); sb.Append(_argInfo.Count); sb.Append(" arguments.\n"); Debug.LogWarning(sb.ToString()); return(false); } // Arg type. OscArgInfo info = _argInfo[index]; OscArgType type = OscConverter.ToArgType(info.tagByte); if (requestedType != type) { StringBuilder sb = StartBuildingInvalidTryGetString(OscDebug.BuildText(this)); sb.Append("Argument at index "); sb.Append(index); sb.Append(" is not type "); sb.Append(requestedType); sb.Append(" ('"); sb.Append((char)OscConverter.ToTagByte(requestedType)); sb.Append("')"); sb.Append(", it is "); sb.Append(type); sb.Append(" ('"); sb.Append((char)info.tagByte); sb.Append("').\n"); Debug.LogWarning(sb.ToString()); return(false); } // Data capacity. if (index + info.size > _argData.Count) { StringBuilder sb = StartBuildingInvalidTryGetString(OscDebug.BuildText(this)); sb.Append("Argument at index "); sb.Append(index); sb.Append(" has incomplete data\n"); Debug.LogWarning(sb.ToString()); return(false); } return(true); }