Functions - field limits
From The Socknet
field_limits is used by some functions to specify the maximum size of data structures that will be accepted by the function (usually reflecting the maximum size of fields in a database).
Contents |
Specification
POST field_limits
{ function: "register_service"
}
->
{ from: {
protocols: {
"*": { public_data: 4096 }
}
}
}
field_limits must be called via POST.
The request must include the function field which holds a string with a function name.
The response is NOT a specification of the function. That is, you must already know what the specification is in order to understand the response.
The response is used to determine maximum byte-size of fields. Any field given that contains a number is a maximum byte-size, where "byte-size" is interpreted in the next section.
The field names in the response are either a field name from the function's specification or a "*", meaning any field.
The example shown indicates that any field that matches the path from.protocol.*.public_data may contain at most 4096 bytes. Any other field is unrestricted.
Data Types
The meaning of the values given by this function is slightly different depending on the type of data that the field is intended to hold. This is because different data structures will often be stored differently in a database.
String or Number
If a field holds a string the number indicates that the string itself (ie, excluding escapes and quotes) must have character length less than or equal to the amount given. This is irrespective of the number of bytes required to hold a given character.
If the field holds a number, the number should be treated as a string.
Boolean
If the field holds a boolean, the field-limit really isn't necessary, because booleans can fit in any space with at least one bit.
Object
When a field holds an object, the number given indicates the maximum byte-count for the JSON form of that object. JSON is always in UTF-8, therefore the byte-count is equal to the character-count.
Undefined Field Type
If the type that the field should hold is allowed to be any type, then the field acts like an object for the purposes of this function.
Arrays
Limits for arrays may be treated in one of two ways:
If the field in the response contains a number, then the array is treated like an object.
If the field in the response contains an array with exactly one number, then it indicates the limit for items that are in the array. Each item must follow the rules for the expected datatype.
Support
Any Provider or Service that supports a function which requires the use of field_limits must support field_limits (as of now there is only register_service which is only supported by Providers).

