/// Retrieves the first Flattenable value in the given field. /// <param name="name"/> /// <param name="returnObject"> /// A Flattenable object that, on success, will be set to reflect /// the value held in this field. This object will not be referenced /// by this Message. /// </param> public void getFlat(string name, Flattenable returnObject) { MessageField field = getField(name); if (returnObject.allowsTypeCode(field.typeCode())) { object o = field.getData(); if (o is byte[][]) { unflattenFromArray(returnObject, ((byte[][])o)[0]); } else if (o is Message[]) { returnObject.setEqualTo(((Message[])o)[0]); } else if (o is Point[]) { returnObject.setEqualTo(((Point[])o)[0]); } else if (o is Rect[]) { returnObject.setEqualTo(((Rect[])o)[0]); } else { throw new FieldTypeMismatchException(name + " isn't a flattened-data field"); } } else { throw new FieldTypeMismatchException("Passed-in object doesn't like typeCode " + whatString(field.typeCode())); } }
/// Retrieves the contents of the given field as an array of /// Flattenable values. /// <param name="name">Name of the field to look for /// </param> Flattenable values in. /// <param name="returnObjects">Should be an array of pre-allocated /// Flattenable objects of the correct type. On success, this /// array's objects will be set to the proper states as determined by /// the held data in this Message. All the objects should be of the /// same type. This method will unflatten as many objects as exist or /// can fit in the array. These objects will not be referenced by /// this Message.</param> /// <returns>The number of objects in (returnObjects) that were /// actually unflattened. May be less than (returnObjects.length). /// </returns> /// <exception cref="FieldNotFoundException"/> /// <exception cref="FieldTypeMismatchException"/> /// <exception cref="UnflattenFormatException"/> /// <exception cref="InvalidCastException"/> /// public int getFlats(string name, Flattenable [] returnObjects) { MessageField field = getField(name); if (returnObjects[0].allowsTypeCode(field.typeCode())) { object objs = field.getData(); int num; if (objs is byte[][]) { byte [][] bufs = (byte[][])objs; num = (bufs.Length < returnObjects.Length) ? bufs.Length : returnObjects.Length; for (int i = 0; i < num; i++) { unflattenFromArray(returnObjects[i], bufs[i]); } } else if (objs is Message[]) { Message [] messages = (Message[])objs; num = (messages.Length < returnObjects.Length) ? messages.Length : returnObjects.Length; for (int i = 0; i < num; i++) { returnObjects[i].setEqualTo(messages[i]); } } else if (objs is Point[]) { Point [] points = (Point[])objs; num = (points.Length < returnObjects.Length) ? points.Length : returnObjects.Length; for (int i = 0; i < num; i++) { returnObjects[i].setEqualTo(points[i]); } } else if (objs is Rect[]) { Rect [] rects = (Rect[])objs; num = (rects.Length < returnObjects.Length) ? rects.Length : returnObjects.Length; for (int i = 0; i < num; i++) { returnObjects[i].setEqualTo(rects[i]); } } else { throw new FieldTypeMismatchException(name + " wasn't an unflattenable data field"); } return(num); } else { throw new FieldTypeMismatchException("Passed-in objects doen't like typeCode " + whatString(field.typeCode())); } }
public void setRect(string name, Rect val) { MessageField field = getCreateOrReplaceField(name, B_RECT_TYPE); Rect [] array = (Rect[])field.getData(); if ((array == null) || (field.size() != 1)) { array = new Rect[1]; } array[0] = val; field.setPayload(array, 1); }
/// Sets the given field name to contain the flattened bytes of /// the single given Flattenable object. Any previous field contents /// are replaced. The type code of the field is determined by /// calling val.typeCode(). /// (val) will be flattened and the resulting bytes kept. /// (val) does not become part of the Message object. /// <param name="name"/> /// <param name="val"> /// the object whose bytes are to be flattened out and put into /// this field.</param> public void setFlat(string name, Flattenable val) { int type = val.typeCode(); MessageField field = getCreateOrReplaceField(name, type); object payload = field.getData(); switch (type) { // For these types, we have explicit support for holding // the objects in memory, so we'll just clone them case B_MESSAGE_TYPE: { Message [] array = ((payload != null) && (((Message[])payload).Length == 1)) ? ((Message[])payload) : new Message[1]; array[1] = (Message)val.cloneFlat(); field.setPayload(array, 1); } break; case B_POINT_TYPE: { Point [] array = ((payload != null) && (((Point[])payload).Length == 1)) ? ((Point[])payload) : new Point[1]; array[1] = (Point)val.cloneFlat(); field.setPayload(array, 1); } break; case B_RECT_TYPE: { Rect [] array = ((payload != null) && (((Rect[])payload).Length == 1)) ? ((Rect[])payload) : new Rect[1]; array[1] = (Rect)val.cloneFlat(); field.setPayload(array, 1); } break; // For everything else, we have to store the objects as byte buffers default: { byte [][] array = ((payload != null) && (((byte[][])payload).Length == 1)) ? ((byte[][])payload) : new byte[1][]; array[0] = flattenToArray(val, array[0]); field.setPayload(array, 1); } break; } }
/// Sets the given field name to contain a single Message value. /// Any previous field contents are replaced. /// Note that a copy of (val) is NOT made; the passed-in mesage /// object becomes part of this Message. /// /// <param name="name"/> /// <param name="val/> public void setMessage(string name, Message val) { MessageField field = getCreateOrReplaceField(name, B_MESSAGE_TYPE); Message [] array = (Message[])field.getData(); if ((array == null) || (field.size() != 1)) { array = new Message[1]; } array[0] = val; field.setPayload(array, 1); }
public void setPoint(string name, Point val) { MessageField field = getCreateOrReplaceField(name, B_POINT_TYPE); Point [] array = (Point[])field.getData(); if ((array == null) || (field.size() != 1)) { array = new Point[1]; } array[0] = val; field.setPayload(array, 1); }
public void setDouble(string name, double val) { MessageField field = getCreateOrReplaceField(name, B_DOUBLE_TYPE); double [] array = (double[])field.getData(); if ((array == null) || (field.size() != 1)) { array = new double[1]; } array[0] = val; field.setPayload(array, 1); }
public void setString(string name, string val) { MessageField field = getCreateOrReplaceField(name, B_STRING_TYPE); string [] array = (string[])field.getData(); if ((array == null) || (field.size() != 1)) { array = new string[1]; } array[0] = val; field.setPayload(array, 1); }
public void setFloat(string name, float val) { MessageField field = getCreateOrReplaceField(name, B_FLOAT_TYPE); float [] array = (float[])field.getData(); if ((array == null) || (field.size() != 1)) { array = new float[1]; } array[0] = val; field.setPayload(array, 1); }
public void setShort(string name, short val) { MessageField field = getCreateOrReplaceField(name, B_INT16_TYPE); short [] array = (short[])field.getData(); if ((array == null) || (field.size() != 1)) { array = new short[1]; } array[0] = val; field.setPayload(array, 1); }
public void setByte(string name, byte val) { MessageField field = getCreateOrReplaceField(name, B_INT8_TYPE); byte [] array = (byte[])field.getData(); if ((array == null) || (field.size() != 1)) { array = new byte[1]; } array[0] = val; field.setPayload(array, 1); }
/// Sets the given field name to contain a single boolean value. /// Any previous field contents are replaced. /// <param name="Name"/> /// <param name="val"/> /// public void setBoolean(string name, bool val) { MessageField field = getCreateOrReplaceField(name, B_BOOL_TYPE); bool [] array = (bool[])field.getData(); if ((array == null) || (field.size() != 1)) { array = new bool[1]; } array[0] = val; field.setPayload(array, 1); }
/// Sets the given field name to contain a single byte buffer value. Any previous field contents are replaced. /// <param name="name"/> /// <param name="type">The type code to give the field. /// May not be a B_*_TYPE that contains non-byte-buffer /// data (e.g. B_STRING_TYPE or B_INT32_TYPE) /// </param> /// <param name="val">Value that will become the sole value in the /// specified field.</param> /// <exception cref="FieldTypeMismatchException"/> /// public void setByteBuffer(string name, int type, byte[] val) { checkByteBuffersOkay(type); MessageField field = getCreateOrReplaceField(name, type); byte [][] array = (byte[][])field.getData(); if ((array == null) || (field.size() != 1)) { array = new byte[1][]; } array[0] = val; field.setPayload(array, 1); }
/// Sets the given field name to contain the given Flattenable values. /// Any previous field contents are replaced. /// Note that if the objects are Messages, Points, or Rects, /// they will be cloned rather than flattened. /// <param name="name"/> /// <param name="val"> /// Array of Flattenable objects to assign to the field. /// The objects are all flattened and /// the flattened data is put into the Message; /// the objects themselves do not become part of the message. /// </param> public void setFlats(string name, Flattenable [] vals) { int type = vals[0].typeCode(); int len = vals.Length; MessageField field = getCreateOrReplaceField(name, type); // For these types, we have explicit support for holding // the objects in memory, so we'll just clone them switch (type) { case B_MESSAGE_TYPE: { Message [] array = new Message[len]; for (int i = 0; i < len; i++) { array[i] = (Message)vals[i].cloneFlat(); } field.setPayload(array, len); } break; case B_POINT_TYPE: { Point [] array = new Point[len]; for (int i = 0; i < len; i++) { array[i] = (Point)vals[i].cloneFlat(); } field.setPayload(array, len); } break; case B_RECT_TYPE: { Rect [] array = new Rect[len]; for (int i = 0; i < len; i++) { array[i] = (Rect)vals[i].cloneFlat(); } field.setPayload(array, len); } break; default: { byte [][] array = (byte[][])field.getData(); if ((array == null) || (field.size() != len)) { array = new byte[len][]; } for (int i = 0; i < len; i++) { array[i] = flattenToArray(vals[i], array[i]); } field.setPayload(array, len); } break; } }